24.12.21 00:09, Guido van Rossum пише:
> Without decorator too (that was Lukasz’ idea). Why bother with the
> decorator (*if* we were to go there)?

It is errorprone.

Some library provide function foo() which returns an instance of private
type _Foo and people start using it as a type hint. A new version
converts foo() into a class. It is usually a safe backward compatible
change, except that now all type hints became wrong. "a: foo" now means
an instance of foo, not a callable which returns an instance of _Foo.

There are also issues with subclassing.

>>> foo = Callable[[int], str]
>>> class A(foo): ...
...
>>> def bar(x: int, /) -> str: pass
...
>>> class B(bar): ...
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: function() argument 'code' must be code, not str

There are also issues with subscripting:

>>> T = TypeVar('T')
>>> foo = Callable[[T], list[T]]
>>> list[foo][int]
list[typing.Callable[[int], list[int]]]
>>> def bar(x: T, /) -> list[T]: pass
...
>>> list[bar][int]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: There are no type variables left in list[__main__.bar]

_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/ALW5PMZ3MRIG3BGTX5DVIKFO4JS45MBK/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to