-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Comments
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? |
That's right, it can't be enabled for 3.9.0 or 3.9.1. |
flake8-pep585 makes no distinction between any of the 3.9.x versions, and supports this for py39 as a whole. |
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. |
Sorry, I see how pyupgrade went on the safer side. Ruff inherited that and it makes sense. |
A solution for users with Python >=3.9.2,<3.10 could be manually configuring the TID251 rule with:
|
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. |
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
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.
The text was updated successfully, but these errors were encountered: