Skip to content
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

collections.abc.Callable inside Option/Union broken in 3.9.0/3.9.1 #677

Closed
frenck opened this issue Jul 11, 2022 · 1 comment · Fixed by #679
Closed

collections.abc.Callable inside Option/Union broken in 3.9.0/3.9.1 #677

frenck opened this issue Jul 11, 2022 · 1 comment · Fixed by #679

Comments

@frenck
Copy link

frenck commented Jul 11, 2022

The use of collections.abc.Callable inside Optional/Union is broken in Python 3.9.0 and 3.9.1.

Recently, I've bumped pyupgrade from v2.34.0 to v2.37.0 and ran into this issue caused by refactoring done by pyupgrade.

pyupgrade with --py39-plus:

from typing import Any, NamedTuple, Optional

NoParamCallback = Optional[Callable[[object], Any]]
ActivityCallback = Optional[Callable[[object, tuple], Any]]

Results in:

from collections.abc import Callable
from typing import Any, NamedTuple, Optional

NoParamCallback = Optional[Callable[[object], Any]]
ActivityCallback = Optional[Callable[[object, tuple], Any]]

Which triggers: https://bugs.python.org/issue42965

@frenck
Copy link
Author

frenck commented Jul 11, 2022

Thanks for the quick turnaround, appreciated ❤️

The-Compiler added a commit to qutebrowser/qutebrowser that referenced this issue Oct 13, 2024
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.
The-Compiler added a commit to qutebrowser/qutebrowser that referenced this issue Oct 13, 2024
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.
The-Compiler added a commit to qutebrowser/qutebrowser that referenced this issue Oct 15, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant