This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author apaszke
Recipients apaszke
Date 2018-05-03.18:31:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1525372301.54.0.682650639539.issue33420@psf.upfronthosting.co.za>
In-reply-to
Content
Hi everyone,

I have a module that needs to inspect type annotations on a few functions. One of the types I need to special case on is typing.Tuple, and I used code like this to detect it:

if getattr(annotation, '__origin__', None) == typing.Tuple:
    ... 
else:
    ...

This was based on the comment from the typing module (Lib/typing.py:609) that specified this particular invariant on the __origin__ attribute:

> __origin__ keeps a reference to a type that was subscripted,
  e.g., Union[T, int].__origin__ == Union;

Everything worked just fine until I checked it on the alpha release of Python 3.7 in my CI. Turns out, that in that release we have

typing.Tuple[str, int].__origin__ == tuple

and not (which is the case in e.g. 3.6)

typing.Tuple[str, int].__origin__ == typing.Tuple


I know this is not a documented attribute, so it can change, but I wanted to highlight that it's either a regression, or the comment will need to be updated, so people won't try to depend on that.
History
Date User Action Args
2018-05-03 18:31:41apaszkesetrecipients: + apaszke
2018-05-03 18:31:41apaszkesetmessageid: <1525372301.54.0.682650639539.issue33420@psf.upfronthosting.co.za>
2018-05-03 18:31:41apaszkelinkissue33420 messages
2018-05-03 18:31:41apaszkecreate