-
-
Notifications
You must be signed in to change notification settings - Fork 184
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
if sys.version_info blocks without an else get rewritten via the pre-commit hook #931
Comments
this was intentionally changed at some point. there are a few cases where it still leaves an else less one but when it deems it safe it can |
Is it intentional that the behavior differs between the pre-commit hook and the command line, though? Similarly, is it intentional/safe that it deletes the next comment? |
you are comparing 3.3.1 vs 3.15.0 what do you expect? |
Ok, if I update my local
|
the end of the block is not well defined when there's trialing comments -- pyupgrade picks the approach based on the information the tokenization hands it -- there isn't a correct choice because people do all sorts of flavors of:
etc. the docs aren't really out of date since there are still cases where it will leave an elseless branch alone -- but enumerating them in the docs isn't useful |
the case the docs is specifically referring to (where it will introduce a syntax error) is:
|
Fair points, thanks. |
In the section on Python2 and old Python3.x blocks, the README states:
However I have noticed that some of my else-less if blocks for checking old Python versions get deleted by the
pyupgrade
pre-commit
hook.Minimal steps to replicate:
Not only does the
pre-commit
hook rewrite (delete) theif
block unexpectedly, it also deletes the next comment (# run setup
)! As a result, mytest.py
afterpre-commit
looks likewhere the remaining comment now pertains to the wrong line of code.
Version info:
pyupgrade 3.3.1
pre-commit 2.20.0
python 3.9.13
The text was updated successfully, but these errors were encountered: