mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
gh-112345: typing.Protocol
: Let failed subclasscheck show non-method members (#112344)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
parent
d9fc15222e
commit
e9d1360c9a
3 changed files with 25 additions and 1 deletions
|
@ -4091,6 +4091,22 @@ class ProtocolTests(BaseTestCase):
|
|||
self.assertIsInstance(Foo(), ProtocolWithMixedMembers)
|
||||
self.assertNotIsInstance(42, ProtocolWithMixedMembers)
|
||||
|
||||
def test_protocol_issubclass_error_message(self):
|
||||
class Vec2D(Protocol):
|
||||
x: float
|
||||
y: float
|
||||
|
||||
def square_norm(self) -> float:
|
||||
return self.x ** 2 + self.y ** 2
|
||||
|
||||
self.assertEqual(Vec2D.__protocol_attrs__, {'x', 'y', 'square_norm'})
|
||||
expected_error_message = (
|
||||
"Protocols with non-method members don't support issubclass()."
|
||||
" Non-method members: 'x', 'y'."
|
||||
)
|
||||
with self.assertRaisesRegex(TypeError, re.escape(expected_error_message)):
|
||||
issubclass(int, Vec2D)
|
||||
|
||||
|
||||
class GenericTests(BaseTestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue