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

UP035: Rewrite typing.Callable to collections.abc.Callable for Python 3.9.2+ #2690

Closed
ngnpope opened this issue Feb 9, 2023 · 7 comments
Closed
Labels
question Asking for support or clarification

Comments

@ngnpope
Copy link
Contributor

ngnpope commented Feb 9, 2023

There was a bug in Python 3.9.0 and 3.9.1 which resulted in pyupgrade only making this rewrite on 3.10+.

The issue was resolved in Python 3.9.2 and we're now on Python 3.9.16. It seems a shame to not support this.

See asottile/pyupgrade#677 for context.

@charliermarsh
Copy link
Member

We probably need to support minor version-based minimums in order to do this, right? Like, we can't enable this for all Python 3.9.X versions, can we?

@charliermarsh charliermarsh added the question Asking for support or clarification label Feb 9, 2023
@ngnpope
Copy link
Contributor Author

ngnpope commented Feb 9, 2023

That's right, it can't be enabled for 3.9.0 or 3.9.1.

@ericbn
Copy link
Contributor

ericbn commented Mar 8, 2023

flake8-pep585 makes no distinction between any of the 3.9.x versions, and supports this for py39 as a whole.

@charliermarsh
Copy link
Member

I think those suggestions are technically incorrect for Python 3.9.0 and Python 3.9.1 though. If you make those changes, your imports will fail on those specific minor versions.

@ericbn
Copy link
Contributor

ericbn commented Mar 8, 2023

Sorry, I see how pyupgrade went on the safer side. Ruff inherited that and it makes sense.

@ericbn
Copy link
Contributor

ericbn commented Mar 9, 2023

A solution for users with Python >=3.9.2,<3.10 could be manually configuring the TID251 rule with:

[tool.ruff.flake8-tidy-imports]
[tool.ruff.flake8-tidy-imports.banned-api]
"typing.Callable".msg = "Use collections.abc.Callable instead."

@ngnpope
Copy link
Contributor Author

ngnpope commented Mar 9, 2023

That's a neat workaround. I'm using 3.9+ everywhere so it's viable.

I would hope that people aren't using .0 or .1 by now, but reality is never the ideal. I guess you can close this @charliermarsh if you're not wanting to special case this to check the patch version.

@charliermarsh charliermarsh closed this as not planned Won't fix, can't repro, duplicate, stale Jul 10, 2023
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
question Asking for support or clarification
Projects
None yet
Development

No branches or pull requests

3 participants