mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
gh-74690: Don't set special protocol attributes on non-protocol subclasses of protocols (#104622)
Don't set special protocol attributes on non-protocol subclasses of protocols
This commit is contained in:
parent
aab2a366b7
commit
f7835fc7e9
2 changed files with 22 additions and 6 deletions
|
@ -3167,6 +3167,21 @@ class ProtocolTests(BaseTestCase):
|
|||
self.assertIsInstance(NonPR(), PR)
|
||||
self.assertIsSubclass(NonPR, PR)
|
||||
|
||||
self.assertNotIn("__protocol_attrs__", vars(NonP))
|
||||
self.assertNotIn("__protocol_attrs__", vars(NonPR))
|
||||
self.assertNotIn("__callable_proto_members_only__", vars(NonP))
|
||||
self.assertNotIn("__callable_proto_members_only__", vars(NonPR))
|
||||
|
||||
acceptable_extra_attrs = {
|
||||
'_is_protocol', '_is_runtime_protocol', '__parameters__',
|
||||
'__subclasshook__', '__abstractmethods__', '_abc_impl',
|
||||
'__init__', '__annotations__',
|
||||
}
|
||||
self.assertLessEqual(vars(NonP).keys(), vars(C).keys() | acceptable_extra_attrs)
|
||||
self.assertLessEqual(
|
||||
vars(NonPR).keys(), vars(D).keys() | acceptable_extra_attrs
|
||||
)
|
||||
|
||||
def test_custom_subclasshook(self):
|
||||
class P(Protocol):
|
||||
x = 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue