[New-bugs-announce] [issue32752] no information about accessing typing.Generic type arguments

Paul Pinterits report at bugs.python.org
Fri Feb 2 17:59:06 EST 2018


New submission from Paul Pinterits <rawing7 at gmail.com>:

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.

----------
assignee: docs at python
components: Documentation
messages: 311520
nosy: Paul Pinterits, docs at python
priority: normal
severity: normal
status: open
title: no information about accessing typing.Generic type arguments
type: enhancement
versions: Python 3.5, Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32752>
_______________________________________


More information about the New-bugs-announce mailing list