Ken Jin <kenjin4...@gmail.com> added the comment:

@Serhiy a summary from what I understand. I hope this helps:

> I am confused. Why do these objects should have __name__ and __qualname__ 
> attributes? What document specifies this?

I don't think any doc specifies this. The docs for __name__ and __qualname__ 
say they apply only to "name of the class, function, method, descriptor, or 
generator instance". The typing "types" are objects, not classes, so normally 
they wouldn't apply, but maybe there is an exception (see below).

> How are these attributes used?

According to OP, for logging/printing purposes. Initially, I was slightly 
against adding this. But I realized that it make sense for ABCs and concrete 
classes. PEP 585 says that the builtin types.GenericAlias is a "thin proxy type 
that forwards all method calls and attribute accesses to the bare origin 
type"[1] with some exceptions. typing._GenericAlias is supposed to behave 
similarly to builtin version.

>>> list[int].__name__
'list'
>>> collections.abc.Callable[[int], str].__name__
'Callable'

Both typing.List[int].__name__ and typing.Callable[int].__name__ raised error 
before Yurii's PR. So I think it's good that we aligned typing's behavior and 
the builtin version.

[1] 
https://www.python.org/dev/peps/pep-0585/#parameters-to-generics-are-available-at-runtime

I just realized Łukasz wrote PEP 585, so maybe he can shed some insight too.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue44524>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to