Skip to content

typing: minor changes #3933

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 4 commits into from
Apr 22, 2020
Merged

typing: minor changes #3933

merged 4 commits into from
Apr 22, 2020

Conversation

hauntsaninja
Copy link
Collaborator

No description provided.

@hauntsaninja
Copy link
Collaborator Author

Happy to split this PR up / not squash-merge it, if that makes sense for any reason.

hauntsaninja added 3 commits April 20, 2020 19:25
For py37 and above, this is _GenericAlias, for py36 and below it's
_TypeAlias. I don't think we need to make typing.pyi definitions
correspond more precisely, but we should avoid leaking a
typing.TypeAlias class
Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

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

I am slightly worried about the TypeAlias renaming, but the tests pass and the change is sensible.

@srittau srittau merged commit 496d758 into python:master Apr 22, 2020
@hauntsaninja hauntsaninja deleted the typing branch April 23, 2020 00:05
@hauntsaninja
Copy link
Collaborator Author

Definitely a nervous PR!

facebook-github-bot pushed a commit to facebook/pyre-check that referenced this pull request Jun 3, 2020
Summary:
PEP 560 removed `typing.GenericMeta`, so it was conditionally removed from typeshed by python/typeshed#3933 .

However, we rely on that class to be the metaclass of `Generic`, all generic classes, and all protocols.  This meant that once typeshed was updated, lots of attributes disappeared.

This diff fixes that by special casing it back in.  This means we'll erroneously allow users to refer to it, but that's fine for now.

Reviewed By: grievejia

Differential Revision: D21854250

fbshipit-source-id: 294740a866800b70939f425e8919a3c275b36285
vishalkuo pushed a commit to vishalkuo/typeshed that referenced this pull request Jun 26, 2020
* typing: fix argument names of cast
* typing: use private _Alias class

For py37 and above, this is _GenericAlias, for py36 and below it's
_TypeAlias. I don't think we need to make typing.pyi definitions
correspond more precisely, but we should avoid leaking a
typing.TypeAlias class
@shannonzhu
Copy link
Contributor

https://www.python.org/dev/peps/pep-0613/

Pep613 for explicit aliases actually relies on TypeAlias being defined in typing. I'm not sure if this PEP is supported in type checkers outside of Pyre at the moment, but this change ended up breaking the feature for us. Will see if I can revert this renaming and add some tests.

@hauntsaninja
Copy link
Collaborator Author

hauntsaninja commented Jul 22, 2020

The TypeAlias removed in this PR is actually unrelated to PEP 613, and is instead meant to reflect typing internals in CPython that were removed (the _TypeAlias class). The confusion is understandable though, and I'm sorry for breaking Pyre :-(

Given that PEP 613 is accepted, I'd certainly accept a PR on the lines of #4243 (or whatever closes matches the expected implementation of TypeAlias within CPython). This would preferably be gated by the appropriate sys.version_info, but we're probably flexible on that point if it can't be worked around (e.g., Protocol is not version gated, but Literal is).

@shannonzhu
Copy link
Contributor

shannonzhu commented Jul 22, 2020

@hauntsaninja Thanks for the quick response, adding this to typing extensions stubs seems reasonable to me. The #4243 PR ends up defining TypeAlias as an object rather than something that can itself be used as a type, so will propose a change there

Edit: #4354

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.

3 participants