diff --git a/gaphas/aspect.py b/gaphas/aspect.py index 45412e6..eea33b4 100644 --- a/gaphas/aspect.py +++ b/gaphas/aspect.py @@ -2,39 +2,13 @@ Aspects form intermediate items between tools and items. """ -import warnings -from functools import singledispatch as real_singledispatch +from functools import singledispatch from gi.repository import Gdk from gaphas.item import Element -def singledispatch(func): - """Wrapper around singledispatch(), with an extra compatibility function so - code will not break when upgrading from 1.0 to 1.1.""" - wrapped = real_singledispatch(func) - - def when_type(*types): - if not types: - raise TypeError("should provide at least one type") - warnings.warn( - "when_type: is deprecated, use `register` instead", - category=DeprecationWarning, - stacklevel=2, - ) - - def wrapper_for_types(func): - for cls in types: - wrapped.register(cls, func) - return func - - return wrapper_for_types - - wrapped.when_type = when_type # type: ignore[attr-defined] - return wrapped - - class ItemFinder: """Find an item on the canvas.""" diff --git a/tests/test_singledispatch.py b/tests/test_singledispatch.py deleted file mode 100644 index 0aa91c6..0000000 --- a/tests/test_singledispatch.py +++ /dev/null @@ -1,53 +0,0 @@ -import pytest - -from gaphas.aspect import singledispatch - - -class Custom: - pass - - -class Another: - pass - - -@singledispatch -def f(o): - return object, o - - -@f.register(str) -def _str_dispatcher(s): - return str, s - - -@f.when_type(int) -def _int_dispatcher(i): - return int, i - - -@f.when_type(Custom, float) -def _bool_float_dispatcher(i): - return Custom, i - - -def test_singledispatch_with_registered_function(): - assert (str, "abc") == f("abc") - - -def test_singledispatch_with_when_type_function(): - assert (int, 3) == f(3) - - -def test_singledispatch_with_when_type_function_and_multiple_types(): - custom = Custom() - assert (Custom, 3.0) == f(3.0) - assert (Custom, custom) == f(custom) - - -def test_singledispatch_with_when_type_and_no_types(): - with pytest.raises(TypeError): - - @f.when_type() - def errorous(): - pass