From 99c8b340918692d062ea9d0f8f92963bc57d8ffa Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 19 Jan 2026 16:48:32 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/psf/black-pre-commit-mirror: 25.12.0 → 26.1.0](https://github.com/psf/black-pre-commit-mirror/compare/25.12.0...26.1.0) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c43247a..c48ef8f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/psf/black-pre-commit-mirror - rev: 25.12.0 + rev: 26.1.0 hooks: - id: black args: [--safe, --quiet] From ef16a176b8fe3bcd4c07586be6473a48bd0a1180 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 19 Jan 2026 16:49:49 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- setup.py | 1 + .../foundation/_tests/test_cached_method.py | 18 ++-- src/oop_ext/foundation/_tests/test_types.py | 4 +- .../foundation/_tests/test_weak_ref.py | 4 +- src/oop_ext/foundation/cached_method.py | 2 +- src/oop_ext/foundation/callback/_callback.py | 25 +++--- .../foundation/callback/_priority_callback.py | 4 +- src/oop_ext/foundation/callback/_shortcuts.py | 8 +- .../callback/_tests/test_callback.py | 4 +- .../callback/_tests/test_typed_callback.py | 54 ++++-------- .../foundation/callback/_typed_callback.py | 29 +++---- src/oop_ext/foundation/compat.py | 1 + src/oop_ext/foundation/decorators.py | 1 + src/oop_ext/foundation/immutable.py | 11 ++- src/oop_ext/foundation/odict.py | 2 +- src/oop_ext/foundation/types_.py | 1 + src/oop_ext/foundation/weak_ref.py | 12 +-- src/oop_ext/interface/_interface.py | 21 ++--- .../interface/_tests/test_interface.py | 84 ++++++++----------- 19 files changed, 130 insertions(+), 156 deletions(-) diff --git a/setup.py b/setup.py index 8c0bd71..bd9bc65 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- """The setup script.""" + import io from setuptools import find_packages from setuptools import setup diff --git a/src/oop_ext/foundation/_tests/test_cached_method.py b/src/oop_ext/foundation/_tests/test_cached_method.py index 6121b77..5220234 100644 --- a/src/oop_ext/foundation/_tests/test_cached_method.py +++ b/src/oop_ext/foundation/_tests/test_cached_method.py @@ -107,27 +107,27 @@ def Foo(self, par): return "%s %d" % (par, self.id) alpha = TestObject() - alpha.Foo = AttributeBasedCachedMethod( # type:ignore[assignment] + alpha.Foo = AttributeBasedCachedMethod( # type: ignore[assignment] alpha.Foo, "id", cache_size=3 ) - alpha.Foo("test1") # type:ignore[misc] - alpha.Foo("test1") # type:ignore[misc] + alpha.Foo("test1") # type: ignore[misc] + alpha.Foo("test1") # type: ignore[misc] assert alpha.n_calls == 1 - alpha.Foo("test2") # type:ignore[misc] + alpha.Foo("test2") # type: ignore[misc] assert alpha.n_calls == 2 - assert len(alpha.Foo._results) == 2 # type:ignore[attr-defined] + assert len(alpha.Foo._results) == 2 # type: ignore[attr-defined] alpha.id = 3 - alpha.Foo("test2") # type:ignore[misc] + alpha.Foo("test2") # type: ignore[misc] assert alpha.n_calls == 3 - assert len(alpha.Foo._results) == 3 # type:ignore[attr-defined] + assert len(alpha.Foo._results) == 3 # type: ignore[attr-defined] - alpha.Foo("test3") # type:ignore[misc] + alpha.Foo("test3") # type: ignore[misc] assert alpha.n_calls == 4 - assert len(alpha.Foo._results) == 3 # type:ignore[attr-defined] + assert len(alpha.Foo._results) == 3 # type: ignore[attr-defined] @pytest.fixture diff --git a/src/oop_ext/foundation/_tests/test_types.py b/src/oop_ext/foundation/_tests/test_types.py index 5480056..27f6b6f 100644 --- a/src/oop_ext/foundation/_tests/test_types.py +++ b/src/oop_ext/foundation/_tests/test_types.py @@ -26,10 +26,10 @@ def testNull() -> None: n.method1().attr1 n.attr1 = "value" - n.attr1.attr2 = "value" # type:ignore[attr-defined] + n.attr1.attr2 = "value" # type: ignore[attr-defined] del n.attr1 - del n.attr1.attr2.attr3 # type:ignore[attr-defined] + del n.attr1.attr2.attr3 # type: ignore[attr-defined] # Iteration for _ in n: diff --git a/src/oop_ext/foundation/_tests/test_weak_ref.py b/src/oop_ext/foundation/_tests/test_weak_ref.py index 66e989d..264c5a6 100644 --- a/src/oop_ext/foundation/_tests/test_weak_ref.py +++ b/src/oop_ext/foundation/_tests/test_weak_ref.py @@ -510,13 +510,13 @@ def testWeakList() -> None: def m1() -> None: "Never called" - weak_list.append(m1) # type:ignore[arg-type] + weak_list.append(m1) # type: ignore[arg-type] assert 1 == len(weak_list[:]) del m1 assert 0 == len(weak_list[:]) s = _Stub() - weak_list.append(s.Method) # type:ignore[arg-type] + weak_list.append(s.Method) # type: ignore[arg-type] assert 1 == len(weak_list[:]) ref_s = weakref.ref(s) del s diff --git a/src/oop_ext/foundation/cached_method.py b/src/oop_ext/foundation/cached_method.py index aba810a..d4932f2 100644 --- a/src/oop_ext/foundation/cached_method.py +++ b/src/oop_ext/foundation/cached_method.py @@ -148,7 +148,7 @@ def DoClear(self) -> None: def _GetCacheResult(self, key: Hashable, result: ResultType) -> ResultType: # This could return None (_result is Optional), but not doing an assert # here to avoid breaking code. - return self._result # type:ignore[return-value] + return self._result # type: ignore[return-value] class AttributeBasedCachedMethod(CachedMethod, Generic[ResultType]): diff --git a/src/oop_ext/foundation/callback/_callback.py b/src/oop_ext/foundation/callback/_callback.py index 5eee899..b7c0329 100644 --- a/src/oop_ext/foundation/callback/_callback.py +++ b/src/oop_ext/foundation/callback/_callback.py @@ -49,6 +49,7 @@ def on_x(x: int) -> None: is registered with :meth:`Contains `, and unregister all connected functions with :meth:`UnregisterAll `. """ + import types from typing import Any from typing import Optional @@ -192,16 +193,16 @@ def _GetKey( func = func.OriginalMethod() try: - if func.__self__ is not None: # type:ignore[union-attr] + if func.__self__ is not None: # type: ignore[union-attr] # bound method return ( - id(func.__self__), # type:ignore[union-attr] - id(func.__func__), # type:ignore[union-attr] - id(func.__self__.__class__), # type:ignore[union-attr] + id(func.__self__), # type: ignore[union-attr] + id(func.__func__), # type: ignore[union-attr] + id(func.__self__.__class__), # type: ignore[union-attr] ) else: return ( - id(func.__func__), # type:ignore[union-attr] + id(func.__func__), # type: ignore[union-attr] id(GetClassForUnboundMethod(func)), ) @@ -240,20 +241,20 @@ def on_die(r: Any) -> None: try: if ( - func.__self__ is not None # type:ignore[union-attr] - and func.__func__ is not None # type:ignore[union-attr] + func.__self__ is not None # type: ignore[union-attr] + and func.__func__ is not None # type: ignore[union-attr] ): # bound method return ( - weakref.ref(func.__self__), # type:ignore[union-attr] - func.__func__, # type:ignore[union-attr] - func.__self__.__class__, # type:ignore[union-attr] + weakref.ref(func.__self__), # type: ignore[union-attr] + func.__func__, # type: ignore[union-attr] + func.__self__.__class__, # type: ignore[union-attr] ) else: # unbound method return ( None, - func.__func__, # type:ignore[union-attr] + func.__func__, # type: ignore[union-attr] GetClassForUnboundMethod(func), ) except AttributeError: @@ -424,7 +425,7 @@ def Contains( if func_func == real_func: return True try: - f = real_func.__func__ # type:ignore[union-attr] + f = real_func.__func__ # type: ignore[union-attr] except AttributeError: return False else: diff --git a/src/oop_ext/foundation/callback/_priority_callback.py b/src/oop_ext/foundation/callback/_priority_callback.py index 8879166..4044177 100644 --- a/src/oop_ext/foundation/callback/_priority_callback.py +++ b/src/oop_ext/foundation/callback/_priority_callback.py @@ -20,7 +20,7 @@ class PriorityCallback(Callback): INFO_POS_PRIORITY = 3 @Override(Callback._GetInfo) - def _GetInfo( # type:ignore[misc, override] + def _GetInfo( # type: ignore[misc, override] self, func: Callable, priority: int ) -> Any: """ @@ -33,7 +33,7 @@ def _GetInfo( # type:ignore[misc, override] return info + (priority,) @Override(Callback.Register) - def Register( # type:ignore[misc, override] + def Register( # type: ignore[misc, override] self, func: Callable, extra_args: tuple[object, ...] = Callback._EXTRA_ARGS_CONSTANT, diff --git a/src/oop_ext/foundation/callback/_shortcuts.py b/src/oop_ext/foundation/callback/_shortcuts.py index 1cc9e1c..8f0d482 100644 --- a/src/oop_ext/foundation/callback/_shortcuts.py +++ b/src/oop_ext/foundation/callback/_shortcuts.py @@ -174,7 +174,7 @@ def _GetWrapped(method: Method | _MethodWrapper | Callable) -> _MethodWrapper | if isinstance(method, _MethodWrapper): return method try: - return method._wrapped_instance # type:ignore[attr-defined, union-attr] + return method._wrapped_instance # type: ignore[attr-defined, union-attr] except AttributeError: return None @@ -194,7 +194,7 @@ def WrapForCallback(method: Method | _MethodWrapper | Callable) -> _MethodWrappe # Note that the other way around does not work at all (i.e.: if a callback is first added # to the instance, there's no way we'll find about that when adding it to the class # anyways). - if method.__self__ is None: # type:ignore[union-attr] + if method.__self__ is None: # type: ignore[union-attr] if wrapped._method._obj is None: return wrapped @@ -208,10 +208,10 @@ def call(*args: object, **kwargs: object) -> Any: return wrapper(*args, **kwargs) call.__name__ = method.__name__ - call._wrapped_instance = wrapper # type:ignore[attr-defined] + call._wrapped_instance = wrapper # type: ignore[attr-defined] setattr(GetClassForUnboundMethod(method), method.__name__, call) else: # override the instance method - setattr(method.__self__, method.__name__, wrapper) # type:ignore[union-attr] + setattr(method.__self__, method.__name__, wrapper) # type: ignore[union-attr] return wrapper diff --git a/src/oop_ext/foundation/callback/_tests/test_callback.py b/src/oop_ext/foundation/callback/_tests/test_callback.py index 9782b78..6adfe42 100644 --- a/src/oop_ext/foundation/callback/_tests/test_callback.py +++ b/src/oop_ext/foundation/callback/_tests/test_callback.py @@ -53,8 +53,8 @@ def restore_test_classes() -> Generator[None, None, None]: original_c_foo = C.foo yield - Stub.call = original_stub_call # type:ignore[assignment] - C.foo = original_c_foo # type:ignore[assignment] + Stub.call = original_stub_call # type: ignore[assignment] + C.foo = original_c_foo # type: ignore[assignment] class Test: diff --git a/src/oop_ext/foundation/callback/_tests/test_typed_callback.py b/src/oop_ext/foundation/callback/_tests/test_typed_callback.py index fdbb5b9..f406e64 100644 --- a/src/oop_ext/foundation/callback/_tests/test_typed_callback.py +++ b/src/oop_ext/foundation/callback/_tests/test_typed_callback.py @@ -7,8 +7,7 @@ def testCallback0(type_checker: TypeCheckerFixture) -> None: - type_checker.make_file( - """ + type_checker.make_file(""" from oop_ext.foundation.callback import Callback0 c = Callback0() @@ -16,8 +15,7 @@ def testCallback0(type_checker: TypeCheckerFixture) -> None: def fail(x): pass c.Register(fail) - """ - ) + """) result = type_checker.run() result.assert_errors( [ @@ -26,8 +24,7 @@ def fail(x): pass ] ) - type_checker.make_file( - """ + type_checker.make_file(""" from oop_ext.foundation.callback import Callback0 c = Callback0() @@ -35,15 +32,13 @@ def fail(x): pass def ok(): pass c.Register(ok) - """ - ) + """) result = type_checker.run() result.assert_ok() def testCallback1(type_checker: TypeCheckerFixture) -> None: - type_checker.make_file( - """ + type_checker.make_file(""" from oop_ext.foundation.callback import Callback1 c = Callback1[int]() @@ -55,8 +50,7 @@ def fail(): pass def fail2(x: str): pass c.Register(fail2) - """ - ) + """) result = type_checker.run() result.assert_errors( [ @@ -71,8 +65,7 @@ def fail2(x: str): pass ] ) - type_checker.make_file( - """ + type_checker.make_file(""" from oop_ext.foundation.callback import Callback1 c = Callback1[int]() @@ -80,15 +73,13 @@ def fail2(x: str): pass def ok(x: int): pass c.Register(ok) - """ - ) + """) result = type_checker.run() result.assert_ok() def testPriorityCallback0(type_checker: TypeCheckerFixture) -> None: - type_checker.make_file( - """ + type_checker.make_file(""" from oop_ext.foundation.callback import PriorityCallback0 c = PriorityCallback0() @@ -96,8 +87,7 @@ def testPriorityCallback0(type_checker: TypeCheckerFixture) -> None: def fail(x): pass c.Register(fail, priority=2) - """ - ) + """) result = type_checker.run() result.assert_errors( [ @@ -106,8 +96,7 @@ def fail(x): pass ] ) - type_checker.make_file( - """ + type_checker.make_file(""" from oop_ext.foundation.callback import PriorityCallback0 c = PriorityCallback0() @@ -115,15 +104,13 @@ def fail(x): pass def ok(): pass c.Register(ok, priority=2) - """ - ) + """) result = type_checker.run() result.assert_ok() def testPriorityCallback1(type_checker: TypeCheckerFixture) -> None: - type_checker.make_file( - """ + type_checker.make_file(""" from oop_ext.foundation.callback import PriorityCallback1 c = PriorityCallback1[int]() @@ -135,8 +122,7 @@ def fail(): pass def fail2(x: str): pass c.Register(fail2, priority=2) - """ - ) + """) result = type_checker.run() result.assert_errors( [ @@ -151,8 +137,7 @@ def fail2(x: str): pass ] ) - type_checker.make_file( - """ + type_checker.make_file(""" from oop_ext.foundation.callback import PriorityCallback1 c = PriorityCallback1[int]() @@ -160,8 +145,7 @@ def fail2(x: str): pass def ok(x: int): pass c.Register(ok, priority=2) - """ - ) + """) result = type_checker.run() result.assert_ok() @@ -193,8 +177,7 @@ def gen_signature_and_args(count: int) -> tuple[str, str, str]: sig_too_many, args_too_many, types_too_many = gen_signature_and_args(args_count + 1) sig_ok, args_ok, types_ok = gen_signature_and_args(args_count) - type_checker.make_file( - f""" + type_checker.make_file(f""" from oop_ext.foundation.callback import Callback{args_count} c = Callback{args_count}[{types_ok}]() @@ -210,8 +193,7 @@ def too_many_func({sig_too_many}) -> None: ... def ok_func({sig_ok}) -> None: ... c.Register(ok_func) c({args_ok}) - """ - ) + """) result = type_checker.run() result.assert_errors( [ diff --git a/src/oop_ext/foundation/callback/_typed_callback.py b/src/oop_ext/foundation/callback/_typed_callback.py index 8826b4b..d5b1975 100644 --- a/src/oop_ext/foundation/callback/_typed_callback.py +++ b/src/oop_ext/foundation/callback/_typed_callback.py @@ -15,6 +15,7 @@ Note the separate classes are needed for now, but after Python 3.11, we should be able to implement the generic variants (`pep-0646 `__) into ``Callback`` itself. """ + from typing import TYPE_CHECKING from typing import Generic from typing import TypeVar @@ -36,7 +37,7 @@ class Callback0(Callback): if TYPE_CHECKING: - def __call__(self) -> None: # type:ignore[override] + def __call__(self) -> None: # type: ignore[override] ... def Register( @@ -61,7 +62,7 @@ def Contains( class Callback1(Callback, Generic[T1]): if TYPE_CHECKING: - def __call__(self, v1: T1) -> None: # type:ignore[override] + def __call__(self, v1: T1) -> None: # type: ignore[override] ... def Register( @@ -86,7 +87,7 @@ def Contains( class Callback2(Callback, Generic[T1, T2]): if TYPE_CHECKING: - def __call__(self, v1: T1, v2: T2) -> None: # type:ignore[override] + def __call__(self, v1: T1, v2: T2) -> None: # type: ignore[override] ... def Register( @@ -111,7 +112,7 @@ def Contains( class Callback3(Callback, Generic[T1, T2, T3]): if TYPE_CHECKING: - def __call__(self, v1: T1, v2: T2, v3: T3) -> None: # type:ignore[override] + def __call__(self, v1: T1, v2: T2, v3: T3) -> None: # type: ignore[override] ... def Register( @@ -136,7 +137,7 @@ def Contains( class Callback4(Callback, Generic[T1, T2, T3, T4]): if TYPE_CHECKING: - def __call__( # type:ignore[override] + def __call__( # type: ignore[override] self, v1: T1, v2: T2, v3: T3, v4: T4 ) -> None: ... @@ -162,7 +163,7 @@ def Contains( class Callback5(Callback, Generic[T1, T2, T3, T4, T5]): if TYPE_CHECKING: - def __call__( # type:ignore[override] + def __call__( # type: ignore[override] self, v1: T1, v2: T2, v3: T3, v4: T4, v5: T5 ) -> None: ... @@ -188,7 +189,7 @@ def Contains( class PriorityCallback0(PriorityCallback): if TYPE_CHECKING: - def __call__(self) -> None: # type:ignore[override] + def __call__(self) -> None: # type: ignore[override] ... def Register( @@ -214,9 +215,7 @@ def Contains( class PriorityCallback1(PriorityCallback, Generic[T1]): if TYPE_CHECKING: - def __call__( # type:ignore[override] - self, v1: T1 - ) -> None: ... + def __call__(self, v1: T1) -> None: ... # type: ignore[override] def Register( self, @@ -241,9 +240,7 @@ def Contains( class PriorityCallback2(PriorityCallback, Generic[T1, T2]): if TYPE_CHECKING: - def __call__( # type:ignore[override] - self, v1: T1, v2: T2 - ) -> None: ... + def __call__(self, v1: T1, v2: T2) -> None: ... # type: ignore[override] def Register( self, @@ -268,7 +265,7 @@ def Contains( class PriorityCallback3(PriorityCallback, Generic[T1, T2, T3]): if TYPE_CHECKING: - def __call__( # type:ignore[override] + def __call__( # type: ignore[override] self, v1: T1, v2: T2, v3: T3 ) -> None: ... @@ -295,7 +292,7 @@ def Contains( class PriorityCallback4(PriorityCallback, Generic[T1, T2, T3, T4]): if TYPE_CHECKING: - def __call__( # type:ignore[override] + def __call__( # type: ignore[override] self, v1: T1, v2: T2, v3: T3, v4: T4 ) -> None: ... @@ -322,7 +319,7 @@ def Contains( class PriorityCallback5(PriorityCallback, Generic[T1, T2, T3, T4, T5]): if TYPE_CHECKING: - def __call__( # type:ignore[override] + def __call__( # type: ignore[override] self, v1: T1, v2: T2, v3: T3, v4: T4, v5: T5 ) -> None: ... diff --git a/src/oop_ext/foundation/compat.py b/src/oop_ext/foundation/compat.py index a2eb5b1..e493f09 100644 --- a/src/oop_ext/foundation/compat.py +++ b/src/oop_ext/foundation/compat.py @@ -2,6 +2,7 @@ """ A compatibility module for quirks when porting from py2->py3. """ + from typing import Any diff --git a/src/oop_ext/foundation/decorators.py b/src/oop_ext/foundation/decorators.py index 5964347..c4c0c2f 100644 --- a/src/oop_ext/foundation/decorators.py +++ b/src/oop_ext/foundation/decorators.py @@ -2,6 +2,7 @@ """ Collection of decorator with ONLY standard library dependencies. """ + from typing import TYPE_CHECKING from typing import Any from typing import NoReturn diff --git a/src/oop_ext/foundation/immutable.py b/src/oop_ext/foundation/immutable.py index eda1945..dd37d5c 100644 --- a/src/oop_ext/foundation/immutable.py +++ b/src/oop_ext/foundation/immutable.py @@ -4,6 +4,7 @@ USER: The cache-manager uses this module to generate a valid KEY for its cache dictionary. """ + from typing import Any from typing import Dict from typing import Generic @@ -30,11 +31,9 @@ def RegisterAsImmutable(immutable_type: type[object]) -> None: # Fix it for the copy too! import copy - copy._copy_dispatch[ # type:ignore[attr-defined] + copy._copy_dispatch[ # type: ignore[attr-defined] immutable_type - ] = ( - copy._copy_immutable # type:ignore[attr-defined] - ) + ] = copy._copy_immutable # type: ignore[attr-defined] def AsImmutable(value: Any, return_str_if_not_expected: bool = True) -> Any: @@ -119,10 +118,10 @@ def setdefault(self, k: Any, default: Any = None) -> NoReturn: def popitem(self) -> NoReturn: raise NotImplementedError("dict is immutable") - def update(self, *args: object) -> NoReturn: # type:ignore[override] + def update(self, *args: object) -> NoReturn: # type: ignore[override] raise NotImplementedError("dict is immutable") - def __hash__(self) -> int: # type:ignore[override] + def __hash__(self) -> int: # type: ignore[override] if not hasattr(self, "_hash"): # must be sorted (could give different results for dicts that should be the same # if it's not). diff --git a/src/oop_ext/foundation/odict.py b/src/oop_ext/foundation/odict.py index 943a6cc..bf514f8 100644 --- a/src/oop_ext/foundation/odict.py +++ b/src/oop_ext/foundation/odict.py @@ -47,4 +47,4 @@ def __delitem__(self, key: Hashable | slice) -> None: collections.OrderedDict.__delitem__(self, k) else: - collections.OrderedDict.__delitem__(self, key) # type:ignore[arg-type] + collections.OrderedDict.__delitem__(self, key) # type: ignore[arg-type] diff --git a/src/oop_ext/foundation/types_.py b/src/oop_ext/foundation/types_.py index 331e4cf..30bf5b7 100644 --- a/src/oop_ext/foundation/types_.py +++ b/src/oop_ext/foundation/types_.py @@ -2,6 +2,7 @@ """ Extensions to python native types. """ + from typing import TYPE_CHECKING from typing import Any from typing import NoReturn diff --git a/src/oop_ext/foundation/weak_ref.py b/src/oop_ext/foundation/weak_ref.py index 277c3fe..f3a5acf 100644 --- a/src/oop_ext/foundation/weak_ref.py +++ b/src/oop_ext/foundation/weak_ref.py @@ -182,7 +182,7 @@ def is_dead(self) -> bool: def __eq__(self, other: object) -> bool: try: return ( - type(self) is type(other) and self() == other() # type:ignore[operator] + type(self) is type(other) and self() == other() # type: ignore[operator] ) except: return False @@ -231,7 +231,7 @@ def __call__(self, *args: object, **kwargs: object) -> Any: def __eq__(self, other: object) -> bool: try: func1 = WeakMethodRef.__call__(self) - func2 = WeakMethodRef.__call__(other) # type:ignore[arg-type] + func2 = WeakMethodRef.__call__(other) # type: ignore[arg-type] return type(self) == type(other) and func1 == func2 except: return False @@ -365,7 +365,7 @@ def GetWeakProxy(obj: T) -> T: # smart enough to understand that a function receiving `T` can also receive a `ProxyType[T]` without problems, # but it does not. For this reason, we have to lie here and say this functions returns `T`. if obj is None: - return obj # type:ignore[return-value] + return obj # type: ignore[return-value] if not IsWeakProxy(obj): if IsWeakRef(obj): @@ -374,11 +374,11 @@ def GetWeakProxy(obj: T) -> T: real_obj = obj if inspect.ismethod(real_obj): - return WeakMethodProxy(real_obj) # type:ignore[return-value] + return WeakMethodProxy(real_obj) # type: ignore[return-value] - return weakref.proxy(real_obj) # type:ignore[return-value] + return weakref.proxy(real_obj) # type: ignore[return-value] - return obj # type:ignore[return-value] + return obj # type: ignore[return-value] # Keep the same lambda for weak-refs (to be reused among all places that use GetWeakRef(None) diff --git a/src/oop_ext/interface/_interface.py b/src/oop_ext/interface/_interface.py index a00f1ad..294c9dc 100644 --- a/src/oop_ext/interface/_interface.py +++ b/src/oop_ext/interface/_interface.py @@ -36,6 +36,7 @@ class MyCalculatorImpl(object): """ + from typing import TYPE_CHECKING from typing import Any from typing import Dict @@ -157,7 +158,7 @@ def __getitem__(self, *args: Any, **kwargs: Any) -> Any: self.__implemented_interface, "__getitem__" ) ) - return self.__wrapped.__getitem__(*args, **kwargs) # type:ignore[index] + return self.__wrapped.__getitem__(*args, **kwargs) # type: ignore[index] def __setitem__(self, *args: Any, **kwargs: Any) -> Any: if "__setitem__" not in self.__interface_methods: @@ -166,7 +167,7 @@ def __setitem__(self, *args: Any, **kwargs: Any) -> Any: self.__implemented_interface, "__setitem__" ) ) - return self.__wrapped.__setitem__(*args, **kwargs) # type:ignore[index] + return self.__wrapped.__setitem__(*args, **kwargs) # type: ignore[index] def __repr__(self) -> str: return "" % self.__wrapped @@ -178,7 +179,7 @@ def __call__(self, *args: Any, **kwargs: Any) -> Any: self.__implemented_interface, "__call__" ) ) - return self.__wrapped.__call__(*args, **kwargs) # type:ignore[operator] + return self.__wrapped.__call__(*args, **kwargs) # type: ignore[operator] # Instance to check if we are receiving an argument during Interface.__new__ @@ -608,11 +609,11 @@ class ReadOnlyAttribute(Attribute): # by Interface during runtime when checking if an implementation has the required # attributes. - def Attribute( # type:ignore[empty-body] + def Attribute( # type: ignore[empty-body] attribute_type: type[T], instance: object = ... ) -> T: ... - def ReadOnlyAttribute( # type:ignore[empty-body] + def ReadOnlyAttribute( # type: ignore[empty-body] attribute_type: type[T], instance: object = ... ) -> T: ... @@ -938,7 +939,7 @@ def __call__(self, type_: T) -> T: all_interfaces = curr + interfaces else: all_interfaces = interfaces - namespace.__implements__ = all_interfaces # type:ignore[attr-defined] + namespace.__implements__ = all_interfaces # type: ignore[attr-defined] if not no_check: if IsDevelopment(): # Only doing check in dev mode. @@ -1087,7 +1088,7 @@ def run_simulation(params: SimulationParameters, saver: IDataSaver) -> None: Hopefully this will be improved in the future. """ - x = interface(obj) # type:ignore[call-arg] + x = interface(obj) # type: ignore[call-arg] return x @@ -1108,13 +1109,13 @@ def _GetGenericImplementationSignatures() -> frozenset[inspect.Signature]: uses this information. """ - def func1(*args, **kwargs): # type:ignore[no-untyped-def] + def func1(*args, **kwargs): # type: ignore[no-untyped-def] ... - def func2(self, *args, **kwargs): # type:ignore[no-untyped-def] + def func2(self, *args, **kwargs): # type: ignore[no-untyped-def] ... - def func3(cls, *args, **kwargs): # type:ignore[no-untyped-def] + def func3(cls, *args, **kwargs): # type: ignore[no-untyped-def] ... return frozenset( diff --git a/src/oop_ext/interface/_tests/test_interface.py b/src/oop_ext/interface/_tests/test_interface.py index e102d5d..b547f8a 100644 --- a/src/oop_ext/interface/_tests/test_interface.py +++ b/src/oop_ext/interface/_tests/test_interface.py @@ -81,8 +81,8 @@ class D: assert IsImplementation(C2, I, requires_declaration=True) == False assert not IsImplementation(D, I) == True # nope - assert I(C) is C # type:ignore[comparison-overlap] - assert I(C2) is C2 # type:ignore[comparison-overlap] + assert I(C) is C # type: ignore[comparison-overlap] + assert I(C2) is C2 # type: ignore[comparison-overlap] with pytest.raises(InterfaceError): I() @@ -119,13 +119,11 @@ def foo(self, a): with pytest.raises(AssertionError) as e: TestMissingSignature() - assert str(e.value) == textwrap.dedent( - """ + assert str(e.value) == textwrap.dedent(""" Method C.foo signature: (self, a) differs from defined in interface I - (self, a, b=None)""" - ) + (self, a, b=None)""") def TestMissingSignatureOptional(): @ImplementsInterface(I) @@ -135,13 +133,11 @@ def foo(self, a, b): with pytest.raises(AssertionError) as e: TestMissingSignatureOptional() - assert str(e.value) == textwrap.dedent( - """ + assert str(e.value) == textwrap.dedent(""" Method C.foo signature: (self, a, b) differs from defined in interface I - (self, a, b=None)""" - ) + (self, a, b=None)""") def TestWrongParameterName(): @ImplementsInterface(I) @@ -151,13 +147,11 @@ def foo(self, a, c): with pytest.raises(AssertionError) as e: TestWrongParameterName() - assert str(e.value) == textwrap.dedent( - """ + assert str(e.value) == textwrap.dedent(""" Method C.foo signature: (self, a, c) differs from defined in interface I - (self, a, b=None)""" - ) + (self, a, b=None)""") def testSubclasses() -> None: @@ -240,13 +234,13 @@ class C: pass c1 = C() - c1.foo = 10 # type:ignore[attr-defined] - c1.bar = "hello" # type:ignore[attr-defined] - c1.foobar = 20 # type:ignore[attr-defined] + c1.foo = 10 # type: ignore[attr-defined] + c1.bar = "hello" # type: ignore[attr-defined] + c1.foobar = 20 # type: ignore[attr-defined] a_zoo = Zoo() - a_zoo.zoo = 99 # type:ignore[attr-defined] - c1.a_zoo = a_zoo # type:ignore[attr-defined] + a_zoo.zoo = 99 # type: ignore[attr-defined] + c1.a_zoo = a_zoo # type: ignore[attr-defined] c2 = C() @@ -266,15 +260,15 @@ class C: # must not be true if including an object that doesn't implement IZoo interface expected for # a_zoo attribute - c1.a_zoo = "wrong" # type:ignore[attr-defined] + c1.a_zoo = "wrong" # type: ignore[attr-defined] assert not _IsImplementationFullChecking(c1, I) == True # failed, invalid attr type - c1.a_zoo = a_zoo # type:ignore[attr-defined] + c1.a_zoo = a_zoo # type: ignore[attr-defined] # test if we can set foobar to None - c1.foobar = None # type:ignore[attr-defined] + c1.foobar = None # type: ignore[attr-defined] assert IsImplementation(c1, I) == True # OK - c1.foobar = "hello" # type:ignore[attr-defined] + c1.foobar = "hello" # type: ignore[attr-defined] assert not _IsImplementationFullChecking(c1, I) == True # failed, invalid attr type @@ -334,7 +328,7 @@ def m2(self): m1: _InterfM1 # Proxy will make sure that we only access the attributes/methods declared in the interface if mode == "call": - m1 = _InterfM1(m0) # type:ignore[misc] + m1 = _InterfM1(m0) # type: ignore[misc] else: assert mode == "proxy" m1 = GetProxy(_InterfM1, m0) @@ -363,7 +357,7 @@ def bar(self): assert stub.foo() == 10 with pytest.raises(AttributeError): - stub.bar() # type:ignore[attr-defined] + stub.bar() # type: ignore[attr-defined] def testIsImplementationWithSubclasses() -> None: @@ -442,20 +436,20 @@ def __call__(self): # NOTE: It doesn't matter runtime modifications in the instance, what is really being tested # is the *class* of the object (My) is what is really being tested. m = My() - m.m1 = MyWrongMethod() # type:ignore[assignment] + m.m1 = MyWrongMethod() # type: ignore[assignment] assert IsImplementation(m, _InterfM1) == True - m.m1 = MyRightMethod() # type:ignore[assignment] + m.m1 = MyRightMethod() # type: ignore[assignment] assert IsImplementation(m, _InterfM1) == True # NOTE: Testing behaviour of private methods here. from oop_ext.interface._interface import _IsImplementationFullChecking m = My() - m.m1 = MyWrongMethod() # type:ignore[assignment] + m.m1 = MyWrongMethod() # type: ignore[assignment] assert not _IsImplementationFullChecking(m, _InterfM1) - m.m1 = MyRightMethod() # type:ignore[assignment] + m.m1 = MyRightMethod() # type: ignore[assignment] assert _IsImplementationFullChecking(m, _InterfM1) del m.m1 @@ -518,7 +512,7 @@ def m1(self): _InterfM1, a ) # will try to adapt, as it does not directly implement m1 assert b is not None - b.m1() # type:ignore[attr-defined] + b.m1() # type: ignore[attr-defined] with pytest.raises(AttributeError): getattr(b, "non_existent") @@ -600,10 +594,10 @@ def m3(self, *args, **kwargs): """ """ with pytest.raises(InterfaceError): - AssertImplements(M3(), M3) # type:ignore[arg-type] + AssertImplements(M3(), M3) # type: ignore[arg-type] with pytest.raises(InterfaceError): - IsImplementation(M3(), M3) # type:ignore[arg-type] + IsImplementation(M3(), M3) # type: ignore[arg-type] assert IsImplementation(M3(), _InterfM3, requires_declaration=False) assert not IsImplementation(M3(), _InterfM3, requires_declaration=True) @@ -771,7 +765,7 @@ def something(self, stuff): bar = Bar() stub2 = IBar(bar) with pytest.raises(AttributeError): - stub2(stuff=None) # type:ignore[operator] + stub2(stuff=None) # type: ignore[operator] def testImplementsInterfaceAsBoolError() -> None: @@ -795,7 +789,7 @@ def M1(self): assert IsImplementation(obj, I1) with pytest.raises(RuntimeError): - if ImplementsInterface(obj, I1): # type:ignore[arg-type, truthy-function] + if ImplementsInterface(obj, I1): # type: ignore[arg-type, truthy-function] pytest.fail('Managed to test "if ImplementsInterface(obj, I1):"') @@ -906,7 +900,7 @@ def foo(self, x: float) -> object: @interface.ImplementsInterface(IFoo) class Foo3: - def foo(self, x: int) -> tuple: # type:ignore[empty-body] + def foo(self, x: int) -> tuple: # type: ignore[empty-body] pass @@ -972,8 +966,7 @@ def testInterfaceTypeChecking(type_checker) -> None: """ Check that TypeCheckingSupport makes interfaces recognizable by mypy. """ - type_checker.make_file( - """ + type_checker.make_file(""" from oop_ext.interface import Interface class IAcme(Interface): def Foo(self, a, b=None) -> int: # type:ignore[empty-body] @@ -987,8 +980,7 @@ def Foo(a: IAcme) -> int: return a.Foo(2) Foo(Acme()) - """ - ) + """) result = type_checker.run() result.assert_errors( [ @@ -997,8 +989,7 @@ def Foo(a: IAcme) -> int: ) # Using TypeCheckingSupport, now mypy understands Acme implements IAcme. - type_checker.make_file( - """ + type_checker.make_file(""" from oop_ext.interface import Interface, TypeCheckingSupport class IAcme(Interface, TypeCheckingSupport): def Foo(self, a, b=None) -> int: @@ -1012,8 +1003,7 @@ def Foo(a: IAcme) -> int: return a.Foo(2) Foo(Acme()) - """ - ) + """) result = type_checker.run() result.assert_ok() @@ -1029,24 +1019,24 @@ def testDecorators(register_callback: bool): """Interfaces and the foundation decorators/callbacks need to play nice together.""" class IFoo(Interface): - def GetValues(self, unit: str) -> list[float]: # type:ignore[empty-body] + def GetValues(self, unit: str) -> list[float]: # type: ignore[empty-body] ... @classmethod - def GetCaption(cls) -> str: # type:ignore[empty-body] + def GetCaption(cls) -> str: # type: ignore[empty-body] ... @ImplementsInterface(IFoo) class AbstractFoo: @Implements(IFoo.GetValues) @Abstract - def GetValues(self, unit: str) -> list[float]: # type:ignore[empty-body] + def GetValues(self, unit: str) -> list[float]: # type: ignore[empty-body] ... @classmethod @Implements(IFoo.GetCaption) @Abstract - def GetCaption(cls) -> str: # type:ignore[empty-body] + def GetCaption(cls) -> str: # type: ignore[empty-body] ... class Foo(AbstractFoo):