-
-
Notifications
You must be signed in to change notification settings - Fork 31k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optional callable raises TypeError #87131
Comments
https://docs.python.org/3.9/library/typing.html#callable
Tuple type for arguments makes it work |
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! |
Which deprecated version did you use for typing.Callable? I am facing the same issue with Python 3.9 |
Did run with ruff pretending to use Python 3.10, because otherwise it won't reformat those: ruff check --select 'UP035' --fix --config 'target-version = "py310"' --unsafe-fixes This is because collections.abc.Callable inside Optional[...] and Union[...] is broken with Python 3.9.0 and 3.9.1: asottile/pyupgrade#677 astral-sh/ruff#2690 python/cpython#87131 However, pylint can detect problematic usages (of which we only have one), so we might as well use the new thing everywhere possible for consistency.
Did run with ruff pretending to use Python 3.10, because otherwise it won't reformat those: ruff check --select 'UP035' --fix --config 'target-version = "py310"' --unsafe-fixes This is because collections.abc.Callable inside Optional[...] and Union[...] is broken with Python 3.9.0 and 3.9.1: asottile/pyupgrade#677 astral-sh/ruff#2690 python/cpython#87131 However, pylint can detect problematic usages (of which we only have one), so we might as well use the new thing everywhere possible for consistency.
Did run with ruff pretending to use Python 3.10, because otherwise it won't reformat those: ruff check --select 'UP035' --fix --config 'target-version = "py310"' --unsafe-fixes This is because collections.abc.Callable inside Optional[...] and Union[...] is broken with Python 3.9.0 and 3.9.1: asottile/pyupgrade#677 astral-sh/ruff#2690 python/cpython#87131 However, pylint can detect problematic usages (of which we only have one), so we might as well use the new thing everywhere possible for consistency. Also see #7098
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:
The text was updated successfully, but these errors were encountered: