GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-119180: Add `annotationlib` module to support PEP 649 by JelleZijlstra · Pull Request #119891 · python/cpython

Conversation

@JelleZijlstra

@JelleZijlstra JelleZijlstra commented Jun 1, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

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.

  • Issue: Implement PEP 649 and PEP 749 #119180

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
JelleZijlstra added 30 commits May 20, 2024 09:59
@JelleZijlstra
Add __annotate__ descriptors
985f8df
@JelleZijlstra
fix refleaks
c822ffa
@JelleZijlstra
blurb
e80095e
@JelleZijlstra
Fix some tests
90ff2c4
@JelleZijlstra
regen globals
026c0ff
@JelleZijlstra
Some initial work
7968744
@JelleZijlstra
Add bytecode for adding annotate
4e54197
@JelleZijlstra
compiler changes
4469b32
@JelleZijlstra
Functions work
47d672e
@JelleZijlstra
Raise AssertionError on the wrong format
ab9359c
@JelleZijlstra
Merge remote-tracking branch 'upstream/main' into pep649-compile
e65d55a
@JelleZijlstra
Modules and classes
e50cd62
@JelleZijlstra
attempts
afae5c0
@JelleZijlstra
Fixes
e5a7b1a
@JelleZijlstra
Merge remote-tracking branch 'upstream/main' into pep649-compile
3f26d44
@JelleZijlstra
Fix code object name
31a4471
@JelleZijlstra
Start fixing test_type_annotations
fbb1d88
@JelleZijlstra
Fix class scoping
f452eb2
@JelleZijlstra
unyielding
8c4b4e3
@JelleZijlstra
Fix test_typing
cbf9a3d
@JelleZijlstra
Fix test_type_parmas
5d182fc
@JelleZijlstra
Add test, add to inspect
ce98c19
@JelleZijlstra
Use inspect constants
e0578fc
@JelleZijlstra
test_grammar tweaks
ed16167
@JelleZijlstra
fix test_positional_only_arg
f38de20
@JelleZijlstra
Fix test_module
87baca2
@JelleZijlstra
Fix symtable tests
355d3df
@JelleZijlstra
fix test_pydoc
f9d81b6
@JelleZijlstra
fix test_traceback
dd1f64a
@JelleZijlstra
fix test_opcodes
62f5b3b
JelleZijlstra added 4 commits June 16, 2024 16:44
@JelleZijlstra
Merge remote-tracking branch 'upstream/main' into pep649-inspect
5ec025b
@JelleZijlstra
unused imports
288fad9
@JelleZijlstra
fix test_annotationlib
2e376e0
@JelleZijlstra
Fix tests
2a1c9a9
@rhettinger
rhettinger removed their request for review June 17, 2024 02:18
JelleZijlstra added 2 commits July 20, 2024 19:19
@JelleZijlstra
Merge remote-tracking branch 'upstream/main' into pep649-inspect
f60f435
@JelleZijlstra
Reapply python#120272
1f3a63c
@JelleZijlstra

JelleZijlstra commented Jul 21, 2024

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra
JelleZijlstra requested review from AlexWaygood and carljm July 21, 2024 02:28
@JelleZijlstra JelleZijlstra mentioned this pull request Jul 21, 2024
gh-119180: Use type descriptors to access annotations (PEP 749) #122074
Merged
carljm
carljm approved these changes Jul 23, 2024
View reviewed changes

@carljm carljm left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This looks good to me!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
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
)

@carljm carljm Jul 22, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

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?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JelleZijlstra reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Lib/test/test_annotationlib.py Outdated
def test_expressions(self):
def f(
add: a + b,
sub: a + b,

@carljm carljm Jul 23, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Suggested change
sub: a + b,
sub: a - b,

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JelleZijlstra reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Lib/test/test_annotationlib.py Outdated
anno,
{
"add": "a + b",
"sub": "a + b",

@carljm carljm Jul 23, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Suggested change
"sub": "a + b",
"sub": "a - b",

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/test/test_annotationlib.py
self.assertEqual(annotationlib.get_annotations(int), {})
self.assertEqual(annotationlib.get_annotations(object), {})

def test_custom_metaclass(self):

@carljm carljm Jul 23, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@JelleZijlstra JelleZijlstra Jul 23, 2024

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
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 = ""):

@carljm carljm Jul 23, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JelleZijlstra reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Jul 23, 2024
JelleZijlstra added 2 commits July 23, 2024 13:43
@JelleZijlstra
Merge remote-tracking branch 'upstream/main' into pep649-inspect
5f530b9
@JelleZijlstra
Feedback from Carl
477f8c6
@JelleZijlstra

JelleZijlstra commented Jul 23, 2024

Copy link
Copy Markdown
Member Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra
JelleZijlstra enabled auto-merge (squash) July 23, 2024 20:48
@JelleZijlstra
JelleZijlstra merged commit 7b7b90d into python:main Jul 23, 2024
@bedevere-app bedevere-app Bot removed the awaiting merge label Jul 23, 2024
@JelleZijlstra
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
@JelleZijlstra @AlexWaygood @nohlson
pythongh-119180: Add annotationlib module to support PEP 649 (pytho…
513dd5d
…n#119891)

Co-authored-by: Alex Waygood <[email protected]>
nohlson pushed a commit to nohlson/cpython that referenced this pull request Jul 24, 2024
@JelleZijlstra @AlexWaygood @nohlson
pythongh-119180: Add annotationlib module to support PEP 649 (pytho…
9fd92ac
…n#119891)

Co-authored-by: Alex Waygood <[email protected]>
@hugovk hugovk mentioned this pull request Aug 4, 2024
3.13t has today's date; 3.14t is July 11th deadsnakes/issues#292
Closed
@Zac-HD Zac-HD mentioned this pull request Aug 11, 2024
Update pinned dependencies HypothesisWorks/hypothesis#4082
Closed
@JelleZijlstra JelleZijlstra mentioned this pull request Sep 17, 2024
Make singledispatch only evaluate annotation for dispatched arg #110373
Open
@hroncok hroncok mentioned this pull request Oct 29, 2024
Add typing_extensions.evaluate_forward_ref python/typing_extensions#488
Closed
@Daraan Daraan mentioned this pull request Oct 30, 2024
Add backport of evaluate_forward_ref python/typing_extensions#497
Merged
@yashwanthatla yashwanthatla mentioned this pull request Jun 21, 2025
Replication of original PR #497: Add backport of evaluate_forward_ref yashwanthatla/typing_extensions#5
Open
@johnslavik johnslavik mentioned this pull request Jan 6, 2026
singledispatchmethod raises an error when relying on a forward declaration #86153
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@picnixz picnixz picnixz left review comments
@carljm carljm carljm approved these changes
@ericvsmith ericvsmith Awaiting requested review from ericvsmith ericvsmith is a code owner
@AlexWaygood AlexWaygood Awaiting requested review from AlexWaygood AlexWaygood is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@JelleZijlstra @carljm @picnixz @AlexWaygood
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.