-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
bug: UP007 should be reversed when targeting py37 #3174
Comments
note: just to be a bit more clear about if possible, i'm hoping |
That rule should only be triggered on Python 3.10+, unless you have future annotations enabled (i.e., the file contains |
(We don't flag the reverse.) |
pyupgrade has a flag, |
this totally could be a config issue in fact I suspect it I was simply not able to debug as I was unaware of I now believe feel free to close this as a bug or rename it to be a feature enhancement for reversal rather than a bug, issue solved from my POV! |
I'm gonna close for now, thanks for filing :) |
Does ruff have some kind of immediate mode for testing stuff like this on the command line? In Python, we can use the REPL or do
Could we pipe sample Python code into ruff like:
|
That should work today if you use a dash suffix, like: ❯ echo "from typing import Optional; s: Optional[str] = a" | ruff --target-version=py311 --select UP -
-:1:33: UP007 [*] Use `X | Y` for type annotations
Found 1 error.
[*] 1 potentially fixable with the --fix option. |
% s: str | None = "a" Impressive! |
So it makes send to do the |
The
|
That all looks fine - the conversion should happen if the python version (which defaults to the current version but is settable) is 3.10+, or when PyUpgrade itself does have a "keep runtime annotations" flag (one of very few configuration options!) that will ignore I would like it if there was more granularity in error codes, though - this one could possibly be split, and personally, I'd really like FYI, all parsers support |
<astral-sh/ruff#3174> Bug #31771
<astral-sh/ruff#3174> Bug #31771
This reverts commit af1b4c6. It works with even older Python-version up to 3.7+ when > from __future__ import annotations is used as it converts all PEP-484 type hints to "strings", which then no longer must be valid Python code. <astral-sh/ruff#3174> Bug #31771
currently setting up a repo, and encountered this behaviour. Henryiii absolutely nailed it: There are more and more libraries relying on runtime annotations. My 2-cents is |
If you specifically are using a library that depends on runtime annotations, don't use Using it anyway (especially now as that looks like it's not the "future" of Python) and then asking a very useful simplification to be removed from all code that is using it correctly isn't a good idea. Static typing code is hard. Anything simplifying it is highly appreciated. |
thanks for the library! we love it. found another issue tho, consider the class:
ruff lint throws on the property and will autofix to use a pipe operator when
"UP"
ruleset is selected:this syntax is enabled only in python 3.10+ and breaks applications on an earlier version. in my case, I have
pyproject.toml
with the following subsnippet:two interesting asides:
ruff -V
or some other mechanismThe text was updated successfully, but these errors were encountered: