Closed stephenfin closed 3 months ago
I think this may be a bug introduced in https://github.com/PyCQA/flake8/commit/43266a2e26ec49a55b866c78b295deaebb1debf7. Simplifying the above reproducer:
test.py
key = 'foo'
val = 'bar'
print(f'{{"{key}": "{val}"}}'
checks.py
def foo(logical_line):
print(logical_line)
If we run this we get:
❯ flake8 test.py
key = 'xxx'
val = 'xxx'
print(f'x{x{key}xxxx{val}xx}')
I think we want to get:
❯ flake8 test.py
key = 'xxx'
val = 'xxx'
print(f'xxxxxxxxxxxxxxxxxxxx')
Right?
nope! the method is meant to redact string contents and not code
Then we should have:
print(f'xxx{key}xxxx{val}xxx')
?
ah yes I see the quirk. ugh. the FSTRING_MIDDLE token is misleading for curly braces -- should be an easy fix (pycodestyle will likely need the same fix)
want to try a patch?
want to try a patch?
Done. Apologies in advance for the fuzzy wording: I have no idea what the below code is intended to account for:
(and that's after git blame
ing my way back as far as 23c9091b...)
want to try a patch?
Done. Apologies in advance for the fuzzy wording: I have no idea what the below code is intended to account for:
(and that's after
git blame
ing my way back as far as 23c9091b...)
Not looking at where you blamed back to but a bunch of this was implemented to keep compat with pycodestyle. If you want reasoning it's likely in that project
how did you install flake8?
unmodified output of
flake8 --bug-report
describe the problem
what I expected to happen
Some of the plugins in
hacking
use a combo ofast.parse
andlogical_line
to generate an AST for an individual line that is then fed into anast.NodeVisitor
subclass. These work just fine on Python 3.11 and earlier, but I've noticed they fail under specific circumstances on Python 3.12. I've included a minimal reproducer below. There's a chance I am "holding it wrong" but I'd like to confirm this first.sample code
test.py
checks.py
:tox.ini
:commands ran
If I comment out the
print
statement, I see different results for Python 3.12 compared Pythons 3.10 and 3.11. Under 3.12:Under 3.10 and 3.11:
additional information
The E999 error is associated with line 1 of the file, despite the error actually coming from a plugin. This led me on a wild goose chase as I tried to figure out why flake8 thought my file was invalid Python but Python itself did not. I suspect this might also be user error and I should be handling the potential exception from
ast.parse
in my plugin but again, I just wanted to confirm that this was expected practice.