Skip to content

Conversation

@serhiy-storchaka
Copy link
Member

@serhiy-storchakaserhiy-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

@gvanrossumgvanrossum left a comment

Choose a reason for hiding this comment

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

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

@JelleZijlstraJelleZijlstra left a comment

Choose a reason for hiding this comment

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

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

@gvanrossumgvanrossum left a comment

Choose a reason for hiding this comment

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

All right!

I suppose there’s no consequences for typing_extensions either?

@JelleZijlstra
Copy link
Member

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
Member

@Fidget-SpinnerFidget-Spinner left a comment

Choose a reason for hiding this comment

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

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 ((),).

@gvanrossum
Copy link
Member

Go ahead and merge once tests pass!

@serhiy-storchakaserhiy-storchaka merged commit 15df8f8 into python:mainMar 17, 2022
@serhiy-storchakaserhiy-storchaka deleted the remove-typing-_TypingEmpty branch March 17, 2022 07:52
This was referenced Jun 25, 2022
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-featureA feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@serhiy-storchaka@JelleZijlstra@gvanrossum@Fidget-Spinner@raghavthind2005@the-knights-who-say-ni@bedevere-bot