[New-bugs-announce] [issue42329] typing classes do not have __name__ attributes in 3.7+
Gregory P. Smith
report at bugs.python.org
Wed Nov 11 21:23:03 EST 2020
New submission from Gregory P. Smith <greg at krypto.org>:
Python 3.7-3.10a1:
```
>>> List.__name__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.8/typing.py", line 760, in __getattr__
raise AttributeError(attr)
AttributeError: __name__
>>> type(List)
<class 'typing._SpecialGenericAlias'>
>>> type(List[int])
<class 'typing._GenericAlias'>
```
Python 3.6:
```
>>> from typing import List
>>> List.__name__
'List'
>>> type(List)
<class 'typing.GenericMeta'>
>>> type(List[int])
<class 'typing.GenericMeta'>
```
Is this lack of common meta attributes intentional? It makes the typing types unusual.
We just saw it trip up some code that was expecting everything to have a `__name__` attribute while moving beyond 3.6. Judging by that `__getattr__` implementation it should happen on other common `__` attributes as mentioned in https://docs.python.org/3/library/stdtypes.html?highlight=__name__#special-attributes as well.
----------
components: Library (Lib)
messages: 380801
nosy: gregory.p.smith
priority: normal
severity: normal
stage: needs patch
status: open
title: typing classes do not have __name__ attributes in 3.7+
type: behavior
versions: Python 3.10, Python 3.7, Python 3.8, Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42329>
_______________________________________
More information about the New-bugs-announce
mailing list