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.

classification
Title: typing classes do not have __name__ attributes in 3.7+
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.10, Python 3.9, Python 3.8, Python 3.7
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: gregory.p.smith, gvanrossum, levkivskyi, serhiy.storchaka
Priority: normal Keywords:

Created on 2020-11-12 02:23 by gregory.p.smith, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (5)
msg380801 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2020-11-12 02:23
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.
msg380804 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2020-11-12 04:47
Between 3.6 and 3.7 they stopped being types.

IIRC this enabled optimizations. (Serhiy?)

I don't think this is important, but I suppose you have some code that this breaks?

The name is passed to the constructor of _SpecialGenericAlias, so I'm fine with fixing this, though the backports may get tricky when you get down to 3.7.
msg380807 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2020-11-12 08:36
Not a big deal if we don't, I just found it odd so I figured I'd pose the
question. That it's been in three releases and only just now come up is
pretty telling that isn't critical.

The code in question was trying to identify public functions in a module by
inspecting names and I think they've got a more pedantic way to do that
than their existing code that wouldn't be tripped up by a mere callable
without a __name__.

On Wed, Nov 11, 2020, 8:47 PM Guido van Rossum <report@bugs.python.org>
wrote:

>
> Guido van Rossum <guido@python.org> added the comment:
>
> Between 3.6 and 3.7 they stopped being types.
>
> IIRC this enabled optimizations. (Serhiy?)
>
> I don't think this is important, but I suppose you have some code that
> this breaks?
>
> The name is passed to the constructor of _SpecialGenericAlias, so I'm fine
> with fixing this, though the backports may get tricky when you get down to
> 3.7.
>
> ----------
> nosy: +serhiy.storchaka
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue42329>
> _______________________________________
>
msg380830 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2020-11-12 15:31
So shall we just close this?
msg380841 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2020-11-12 18:48
working as intended, they aren't classes.
History
Date User Action Args
2022-04-11 14:59:38adminsetgithub: 86495
2020-11-12 18:48:18gregory.p.smithsetstatus: open -> closed
resolution: rejected
messages: + msg380841

stage: needs patch -> resolved
2020-11-12 15:31:14gvanrossumsetmessages: + msg380830
2020-11-12 08:36:28gregory.p.smithsetmessages: + msg380807
2020-11-12 04:47:01gvanrossumsetnosy: + serhiy.storchaka
messages: + msg380804
2020-11-12 02:46:32xtreaksetnosy: + gvanrossum, levkivskyi
2020-11-12 02:23:03gregory.p.smithcreate