PyCQA / pycodestyle

Simple Python style checker in one Python file
https://pycodestyle.pycqa.org
Other
5.01k stars 755 forks source link

E275: false positive with f-strings in Python 3.12 #1206

Closed ThiefMaster closed 10 months ago

ThiefMaster commented 10 months ago
[adrian@eluvian:/tmp]> ./testenv-312/bin/flake8 --version
6.1.0 (mccabe: 0.7.0, pycodestyle: 2.11.0, pyflakes: 3.1.0) CPython 3.12.0 on Linux

[adrian@eluvian:/tmp]> ./testenv-311/bin/flake8 --version
6.1.0 (mccabe: 0.7.0, pycodestyle: 2.11.0, pyflakes: 3.1.0) CPython 3.11.6 on Linux

[adrian@eluvian:/tmp]> cat util.py
def bug(wtf):
    return f'in{wtf}'

[adrian@eluvian:/tmp]> ./testenv-311/bin/flake8 util.py
[adrian@eluvian:/tmp]> ./testenv-312/bin/flake8 util.py
util.py:2:16: E275 missing whitespace after keyword

For some reason it seems to expect a space before the {...} inside the f-string. of course this makes no sense, since that would change the resulting string.

ThiefMaster commented 10 months ago

Actually, this seems to happen only if the string part happens to be a valid Python operator. f'lol{wtf}' doesn't trigger the bug, but f'not{wtf}', f'def{wtf}', etc. do.