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

bpo-46981: Remove typing._TypingEmpty #31836

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

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Mar 12, 2022

  • get_args(Tuple[()]) returns now () instead of ((),).
  • Tuple[Unpack[Ts]][()] returns now the result equal to Tuple[()].

https://bugs.python.org/issue46981

* get_args(Tuple[()]) returns now () instead of ((),).
* Tuple[Unpack[Ts]][()] returns now the result equal to Tuple[()].
Copy link
Member

@gvanrossum gvanrossum left a comment

Nice simplification! One thing I wonder about is whether this would break 3rd party frameworks that do runtime introspection of annotations? E.g. pydantic. Who can we ask?

Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Thanks!

I don't think this will affect most runtime type checkers; at most it allows them to remove a special case. I did find a reference to _TypingEmpty in the wild: https://github.com/CedricFR/dataenforce/blob/5dfc5f725d6a69197481061d6e6676fdb221adfd/dataenforce/__init__.py#L88. Seems like an attempt to implement their own version of Generic.

Copy link
Member

@gvanrossum gvanrossum left a comment

All right!

I suppose there’s no consequences for typing_extensions either?

@JelleZijlstra
Copy link
Member

@JelleZijlstra JelleZijlstra commented Mar 13, 2022

I suppose there’s no consequences for typing_extensions either?

I just checked and typing-extensions uses _TypingEmpty only in the 3.6 implementation of Protocol.

Copy link
Contributor

@Fidget-Spinner Fidget-Spinner left a comment

Nice simplification! One thing I wonder about is whether this would break 3rd party frameworks that do runtime introspection of annotations? E.g. pydantic. Who can we ask?

Searching pydantic, it seems that get_args is rarely used. However, I will cc Samuel just to be sure. The last time we had a change in get_type_hints re Union, I sought his opinion too. Maybe this will help him figure things out if one of his tests breaks.

@samuelcolvin a summary of the change, for your info please:

typing.get_args(typing.Tuple[()]) now returns () instead of ((),).

@@ -0,0 +1,2 @@
``typing.get_args(typing.Tuple[()])`` returns now ``()`` instead of
Copy link
Contributor

@Fidget-Spinner Fidget-Spinner Mar 13, 2022

Choose a reason for hiding this comment

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

Suggested change
``typing.get_args(typing.Tuple[()])`` returns now ``()`` instead of
``typing.get_args(typing.Tuple[()])`` now returns ``()`` instead of

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