Author Paul Pinterits
Recipients Paul Pinterits, docs@python
Date 2018-02-02.22:59:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1517612346.62.0.467229070634.issue32752@psf.upfronthosting.co.za>
In-reply-to
Content
The documentation of the typing module explains how to instantiate generic types, but there is no information about how to extract the type arguments from a generic type.

Example:

>>> list_of_ints = typing.List[int]
>>> 
>>> # how do we get <class 'int'> out of list_of_ints?
>>> list_of_ints.???
<class 'int'>

Through trial and error I've discovered list_of_ints.__args__, which *seems* to be what I'm looking for, but since it's never mentioned in the docs, it's unclear whether this __args__ attribute is an implementation detail or not.

Please document the official/intended way to extract type arguments from a Generic.
History
Date User Action Args
2018-02-02 22:59:06Paul Pinteritssetrecipients: + Paul Pinterits, docs@python
2018-02-02 22:59:06Paul Pinteritssetmessageid: <1517612346.62.0.467229070634.issue32752@psf.upfronthosting.co.za>
2018-02-02 22:59:06Paul Pinteritslinkissue32752 messages
2018-02-02 22:59:06Paul Pinteritscreate