Skip to content

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

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

@JelleZijlstra JelleZijlstra 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

@gvanrossum gvanrossum 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-Spinner Fidget-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-storchaka serhiy-storchaka merged commit 15df8f8 into python:main Mar 17, 2022
@serhiy-storchaka serhiy-storchaka deleted the remove-typing-_TypingEmpty branch March 17, 2022 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants