Skip to content
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

Correctly parse and cross-reference unpacked type annotations #13369

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

agraboso
Copy link

Closes #13368

@agraboso
Copy link
Author

Given that this is the first PR after the release of v8.2.0, I'm not sure how to record it in CHANGES.rst.

@AA-Turner AA-Turner added this to the 8.x milestone Feb 20, 2025
@AA-Turner
Copy link
Member

Given that this is the first PR after the release of v8.2.0, I'm not sure how to record it in CHANGES.rst.

I've now updated CHANGES for the 8.3 header. Sorry for the trouble.

A

@AA-Turner AA-Turner modified the milestones: 8.x, 8.3.0 Feb 23, 2025
@agraboso agraboso force-pushed the pep646-args branch 2 times, most recently from 0959703 to 20e8d33 Compare February 26, 2025 20:18
@agraboso
Copy link
Author

Entry added to CHANGES.

@agraboso agraboso force-pushed the pep646-args branch 3 times, most recently from a9b2a27 to 0a874c2 Compare March 8, 2025 14:46
@@ -508,6 +508,28 @@ def test_parse_annotation(app):
),
)

doctree = _parse_annotation('*tuple[str, int]', app.env)
Copy link
Member

Choose a reason for hiding this comment

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

Is *tuple[...] a valid stand-alone type annotation? If not, should we have some validation that Starred only comes after [?

I'm happy to keep things as currently proposed in this PR, just unsure which is the best approach.

Copy link
Author

Choose a reason for hiding this comment

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

It is valid in the context of variadic generics annotations (see https://peps.python.org/pep-0646/#unpacking-tuple-types). In other places it is not, but I worked this out under the assumption that Sphinx is looking to accept all valid Python behaviors, not disallow non-valid ones (that would be neat, but would probably imply reimplementing a huge part of the parser in any Python implementation).

With respect to what you are saying about validating it only comes after [: I came out with this PR to deal with annotations in type signatures in function arguments, not in type parameter specifications alla PEP 695. I am AFK and I don't remember off the top of my head if it does come into parsing the latter. I will look into it as soon as I can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PEP 646-style annotation of *args as a Type Variable Tuple
2 participants