FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-119180: Add `annotationlib` module to support PEP 649 by JelleZijlstra · Pull Request #119891 · python/cpython · GitHub

/ cpython Public

gh-119180: Add annotationlib module to support PEP 649 - #119891

Merged
JelleZijlstra merged 136 commits into
python:mainfrom
JelleZijlstra:pep649-inspect
Jul 23, 2024
Merged

gh-119180: Add annotationlib module to support PEP 649#119891
JelleZijlstra merged 136 commits into
python:mainfrom
JelleZijlstra:pep649-inspect

Conversation

JelleZijlstra commented Jun 1, 2024
edited
Loading

Copy link
Copy Markdown
Member

This PR implements the annotationlib module proposed by PEP-749, as well as related Python changes for PEP-649 and PEP-749.

rhettinger removed their request for review June 17, 2024 02:18

Copy link
Copy Markdown
Member Author

This PR is still ready for review. While we will likely make some change related to metaclasses, that won't materially effect the changes here. I'd like to get this PR landed as a foundation to build the rest of the PEP implementation on, so I'd appreciate any reviews.

carljm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This looks good to me!

Comment thread Lib/annotationlib.py Outdated
Comment on lines +108 to +111
if self.__forward_module__ is not None:
globals = getattr(
sys.modules.get(self.__forward_module__, None), "__dict__", globals
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Since this (if set) will override the above heuristics on lines 97-107 anyway, why not move it above line 97 so that if we get a globals from __forward_module__ we don't need to bother with those other lookups?

Comment thread Lib/test/test_annotationlib.py Outdated
def test_expressions(self):
def f(
add: a + b,
sub: a + b,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
sub: a + b,
sub: a - b,

Comment thread Lib/test/test_annotationlib.py Outdated
anno,
{
"add": "a + b",
"sub": "a + b",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
"sub": "a + b",
"sub": "a - b",

self.assertEqual(annotationlib.get_annotations(int), {})
self.assertEqual(annotationlib.get_annotations(object), {})

def test_custom_metaclass(self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Do you plan to add tests here for the pathological cases with metaclass annotations, or make that change in a separate PR?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'll leave metaclasses to a separate PR (#119180).

Comment thread Lib/test/test_annotationlib.py Outdated

def test_custom_object_with_annotations(self):
class C:
def __init__(self, x: int = 0, y: str = ""):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Are the arguments and their annotations actually related to the test? If not, I'd remove them for clarity about what behavior the test is actually specifying.

Copy link
Copy Markdown
Member Author

Thanks @carljm for the review! I pushed fixes for the issues you identified.

JelleZijlstra enabled auto-merge (squash) July 23, 2024 20:48
JelleZijlstra merged commit 7b7b90d into python:main Jul 23, 2024
JelleZijlstra deleted the pep649-inspect branch July 23, 2024 21:20
nohlson pushed a commit to nohlson/cpython that referenced this pull request Jul 24, 2024
nohlson pushed a commit to nohlson/cpython that referenced this pull request Jul 24, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL