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-132493: lazy evaluation of annotations in typing._proto_hook #132534

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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: add case for class implementing protocol with deferred annotations
  • Loading branch information
felixscherz committed Apr 15, 2025
commit 079cf59663d1fb5848e1f39b75e2b4b737d25e86
12 changes: 11 additions & 1 deletion 12 Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4557,14 +4557,24 @@ class Commentable(Protocol):
def test_isinstance_with_deferred_evaluation_of_annotations(self):
@runtime_checkable
class P(Protocol):
x: undefined
x: undefined | int
def meth(self):
...

class DeferredClass:
x: undefined

class DeferredClassImplementingP:
JelleZijlstra marked this conversation as resolved.
Show resolved Hide resolved
x: undefined | int

def __init__(self):
self.x = 0

def meth(self):
...

self.assertFalse(isinstance(DeferredClass(), P))
self.assertTrue(isinstance(DeferredClassImplementingP(), P))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add a test with a class that does fulfill the protocol.

Also, please add a NEWS entry.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a class that satisfies the protocol and a NEWS entry:)


class GenericTests(BaseTestCase):
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.