Skip to content

Commit 7f7bc3f

Browse files
adamtheturtleclaude
andcommitted
Cover a property member in the regression test
A property is not callable when looked up on the class, so it lands in __non_callable_proto_members__ alongside a plain class attribute. Both subtests fail without the change. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016TM2nkuPFj6FFmZyUJZYUQ
1 parent 307fe8f commit 7f7bc3f

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

Lib/test/test_typing.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3894,22 +3894,32 @@ def test_none_on_non_callable_doesnt_defeat_the_abc_cache(self):
38943894
# class out of ABCMeta's cache and made every isinstance() call walk
38953895
# all of the protocol members again.
38963896
@runtime_checkable
3897-
class P(Protocol):
3897+
class PAttr(Protocol):
38983898
x = 1
38993899

3900+
@runtime_checkable
3901+
class PProperty(Protocol):
3902+
@property
3903+
def x(self) -> int: ...
3904+
39003905
class B:
39013906
x = None
39023907

3903-
self.assertIsInstance(B(), P)
3904-
3905-
# The first check must have cached B as a subclass of P, so the second
3906-
# one may not touch the members at all.
3907-
typing._lazy_load_getattr_static.cache_clear()
3908-
try:
3909-
with patch.object(inspect, "getattr_static", side_effect=AssertionError):
3908+
for P in (PAttr, PProperty):
3909+
with self.subTest(protocol=P.__name__):
3910+
self.assertIn("x", P.__non_callable_proto_members__)
39103911
self.assertIsInstance(B(), P)
3911-
finally:
3912-
typing._lazy_load_getattr_static.cache_clear()
3912+
3913+
# The first check must have cached B as a subclass of P, so
3914+
# the second one may not touch the members at all.
3915+
typing._lazy_load_getattr_static.cache_clear()
3916+
try:
3917+
with patch.object(
3918+
inspect, "getattr_static", side_effect=AssertionError
3919+
):
3920+
self.assertIsInstance(B(), P)
3921+
finally:
3922+
typing._lazy_load_getattr_static.cache_clear()
39133923

39143924
def test_none_on_callable_blocks_implementation(self):
39153925
@runtime_checkable

0 commit comments

Comments
 (0)