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

Support typing_extensions.Unpack #12258

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

picnixz
Copy link
Member

@picnixz picnixz commented Apr 10, 2024

The typing.Unpack construction is supported but not typing_extensions.Unpack because it is treated as a TypeVar instance (this is due to a hack in typing_extensions that sets __class__ to TypeVar).

This is built on top of #12256.

@picnixz picnixz changed the title [feature] Support typing.Unpack and typing_extensions.Unpack [feature] Support typing_extensions.Unpack [part 3] Apr 10, 2024
@picnixz
Copy link
Member Author

picnixz commented Apr 10, 2024

Uh-oh. Good to know that Unpack is capricious actually.

@picnixz picnixz marked this pull request as draft April 10, 2024 08:24
@picnixz picnixz marked this pull request as ready for review April 10, 2024 09:22
@picnixz picnixz marked this pull request as draft April 13, 2024 15:51
@picnixz picnixz marked this pull request as ready for review April 15, 2024 07:43
@AA-Turner AA-Turner changed the title [feature] Support typing_extensions.Unpack [part 3] Support typing.Unpack Apr 23, 2024
@AA-Turner AA-Turner changed the title Support typing.Unpack Support typing_extensions.Unpack Apr 23, 2024
@AA-Turner
Copy link
Member

AA-Turner commented Apr 23, 2024

I've restricted the support for typing_extensions.Unpack to Python 3.9 & 3.10 -- I'm wary of opening the floodgates for typing_extensions, and there is already enough variance without two potential sources of truth for typing constructs.

Other than that, please have a look -- I cleaned up the branch history to work from the latest master, but I think I've kept every relevant change.

A

Copy link
Member Author

@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

I think it should be good. I may need to have a look at python/cpython#118168 though.

sphinx/util/typing.py Outdated Show resolved Hide resolved
@picnixz
Copy link
Member Author

picnixz commented Apr 23, 2024

AH ! I remember that test failure ! Let me check what happened

@picnixz
Copy link
Member Author

picnixz commented Apr 23, 2024

Ah yes, actually, in typing_extensions, the name of the Unpack form is not under __name__ but under _name. So that's why we had the failure.

In addition, with Python 3.11, if you use typing_extensions, then it's not synchronized, so typing.get_origin(typing_extensions.Unpack) gives you typing_extensions.Unpack instead (hence the failure).

@picnixz
Copy link
Member Author

picnixz commented Apr 23, 2024

I'm wary of opening the floodgates for typing_extensions, and there is already enough variance without two potential sources of truth for typing constructs.

The problem is that we 3.11 and 3.12 are not sync'ed for typing_extension, hence the sheningans. In general, they are synced but not in this case.

sphinx/util/typing.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants