GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||
GeezerVison is showing github.com — bpo-46644: No longer accept arbitrary callables as type arguments in generics by serhiy-storchaka · Pull Request #31159 · python/cpython Conversation
|
| return f | ||
|
|
||
|
|
||
| class NewType: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
What was the reason to move this definition?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
_type_check() was used before defining NewType.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Please don't. This will break future innovation in the type system (e.g., making new typing primitives in typing-extensions). We don't need to be strict about allowed types in the typing.py runtime; that's what static type checkers are for. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
In addition, this breaks cpython internal typeforms that need to be able to pass through |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| No longer accept arbitrary callables as type arguments in generics. E.g. | ||
| ``List[chr]`` is now an error. |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This patch does not make List[chr] an error. _type_check is not called in this code path.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It does.
>>> List[chr]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/serhiy/py/cpython/Lib/typing.py", line 317, in inner
return func(*args, **kwds)
^^^^^^^^^^^^^^^^^^^
File "/home/serhiy/py/cpython/Lib/typing.py", line 1126, in __getitem__
params = tuple(_type_check(p, msg) for p in params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/serhiy/py/cpython/Lib/typing.py", line 1126, in <genexpr>
params = tuple(_type_check(p, msg) for p in params)
^^^^^^^^^^^^^^^^^^^
File "/home/serhiy/py/cpython/Lib/typing.py", line 184, in _type_check
raise TypeError(f"{msg} Got {arg!r:.100}.")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Parameters to generic types must be types. Got <built-in function chr>.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
That code path is not used in type annotations; try a: List[chr] to reproduce the lack of error. I suppose it can show up in type aliases or get_type_hints, though.
EDIT: I retract this comment, see https://bugs.python.org/msg412662
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Do typing primitives in typing-extensions subclass any typing class? If yes, it can be included in the list of allowed types. If no, we perhaps could use duck-typing: check for some attributes, like Alternatively we can remove all checks. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Duck typing moves the reason |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.