Repository navigation
Optional callable raises TypeError #87131
Description
Activity
https://docs.python.org/3.9/library/typing.html#callable
Python 3.9.1 (default, Jan 12 2021, 16:45:25) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from typing import Optional >>> from collections.abc import Callable >>> >>> Hasher = Optional[Callable[[bytes], bytes]] Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.9/typing.py", line 262, in inner return func(*args, **kwds) File "/usr/local/lib/python3.9/typing.py", line 339, in __getitem__ return self._getitem(self, parameters) File "/usr/local/lib/python3.9/typing.py", line 463, in Optional return Union[arg, type(None)] File "/usr/local/lib/python3.9/typing.py", line 262, in inner return func(*args, **kwds) File "/usr/local/lib/python3.9/typing.py", line 339, in __getitem__ return self._getitem(self, parameters) File "/usr/local/lib/python3.9/typing.py", line 451, in Union parameters = _remove_dups_flatten(parameters) File "/usr/local/lib/python3.9/typing.py", line 231, in _remove_dups_flatten return tuple(_deduplicate(params)) File "/usr/local/lib/python3.9/typing.py", line 205, in _deduplicate all_params = set(params) TypeError: unhashable type: 'list' >>> >>> from typing import Tuple >>> Hasher = Optional[Callable[Tuple[bytes], bytes]] >>>Tuple type for arguments makes it work
- added3.9 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Jan 19, 2021 I'm using the deprecated typing.Callable instead now and that works
Hello, this issue is a byproduct of bpo-42195. It has already been fixed on Python 3.10, and on Python 3.9.2 (which isn't out yet). You can see the what's new for it here https://docs.python.org/3/whatsnew/3.9.html#notable-changes-in-python-3-9-2.
The expected release date for Python 3.9.2 is Monday, 2021-02-15 according to PEP-596 https://www.python.org/dev/peps/pep-0596/.
For now, I guess you'll have to use the old typing.Callable, then update it in newer versions of Python.
On Python 3.10a4: >>> from typing import Optional >>> from collections.abc import Callable >>> Optional[Callable[[bytes], bytes]] typing.Optional[collections.abc.Callable[[bytes], bytes]]
Ah I see, thanks!
Callable
Which deprecated version did you use for typing.Callable? I am facing the same issue with Python 3.9
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields: