Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-104555: Runtime-checkable protocols: Don't let previous calls to isinstance() influence whether issubclass() raises an exception #104559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
May 17, 2023
Merged
Prev Previous commit
Next Next commit
Simplify test
  • Loading branch information
AlexWaygood committed May 16, 2023
commit f3a4551bbfcbb7cdfb9207af76fc739ea9c19611
12 changes: 6 additions & 6 deletions 12 Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2656,17 +2656,17 @@ class D(PNonCall): ...

def test_no_weird_caching_with_issubclass_after_isinstance(self):
@runtime_checkable
class Spam(Protocol[T]):
x: T
class Spam(Protocol):
x: int

class Eggs(Generic[T]):
def __init__(self, x: T) -> None:
self.x = x
class Eggs:
def __init__(self) -> None:
self.x = 42

# gh-104555: ABCMeta might cache the result of this isinstance check
# if we called super().__instancecheck__ in the wrong place
# in _ProtocolMeta.__instancheck__...
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved
self.assertIsInstance(Eggs(42), Spam)
self.assertIsInstance(Eggs(), Spam)

# ...and if it did, then TypeError wouldn't be raised here!
with self.assertRaises(TypeError):
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.