From e8a2252ffa59b5a648739a71e783af4a53bffcf3 Mon Sep 17 00:00:00 2001 From: Dani Pinyol Date: Fri, 24 Jul 2026 13:01:24 +0200 Subject: [PATCH] fix: not_ to return a Callable not an object Otherwise, mypy complains "error: "object" not callable [operator]" --- assertpy2/assertpy.py | 2 +- tests/test_typing.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/assertpy2/assertpy.py b/assertpy2/assertpy.py index 5f4a667..5945d0a 100644 --- a/assertpy2/assertpy.py +++ b/assertpy2/assertpy.py @@ -722,7 +722,7 @@ class NegatedBuilder: def __init__(self, builder: AssertionBuilder) -> None: self._builder = builder - def __getattr__(self, name: str) -> object: + def __getattr__(self, name: str) -> Callable[..., AssertionBuilder]: if name in _NON_NEGATABLE: raise TypeError(_NON_NEGATABLE[name]) attr = getattr(self._builder, name) diff --git a/tests/test_typing.py b/tests/test_typing.py index 2a33b22..d8980e4 100644 --- a/tests/test_typing.py +++ b/tests/test_typing.py @@ -53,6 +53,7 @@ assert_type(assert_that(bytearray(b"raw")), _BytesAssertion[bytearray]) assert_type(assert_that(len), _CallableAssertion) assert_type(assert_that(object()), AssertionBuilder[object]) + assert_type(assert_that(42).not_.is_equal_to(43), AssertionBuilder[Any]) # The iterable-cluster methods stay on their protocol (return Self), so chaining keeps the type. assert_type(assert_that([1, 2]).satisfies_exactly(lambda x: x > 0, lambda x: x > 1), _IterableAssertion[int])