PyCQA / flake8

flake8 is a python tool that glues together pycodestyle, pyflakes, mccabe, and third-party plugins to check the style and quality of some python code.
https://flake8.pycqa.org
Other
3.39k stars 306 forks source link

Flake8 censors itself, covering errors #1931

Closed hwalinga closed 4 months ago

hwalinga commented 4 months ago

how did you install flake8?

$ python -m pip install flake8

unmodified output of flake8 --bug-report

{
  "platform": {
    "python_implementation": "CPython",
    "python_version": "3.11.2",
    "system": "Linux"
  },
  "plugins": [
    {
      "plugin": "mccabe",
      "version": "0.7.0"
    },
    {
      "plugin": "pycodestyle",
      "version": "2.11.1"
    },
    {
      "plugin": "pyflakes",
      "version": "3.2.0"
    }
  ],
  "version": "7.0.0"
}

describe the problem

what I expected to happen

I expected flake8 to detect errors in f-strings, but it is censoring itself by placing xxxx on them.

sample code

"""
docstring
"""

def func(a, b):
    return a + b

A = f"{func(3 , 2)}"

commands ran

$ flake8 -vv t.py

It missed the whitespace before the comma.

Here is the debug output:

flake8.checker            MainProcess    132 DEBUG    Logical line: """"xxxxxxxxxxx""""
flake8.checker            MainProcess    132 DEBUG    Logical line: "def func(a, b):"
flake8.checker            MainProcess    132 DEBUG    Logical line: "return a + b"
flake8.checker            MainProcess    133 DEBUG    Logical line: "A = f"xxxxxxxxxxxxx""
flake8.main.application   MainProcess    133 INFO     Finished running
flake8.main.application   MainProcess    133 INFO     Reporting errors
flake8.main.application   MainProcess    133 INFO     Found a total of 0 violations and reported 0

I don't know if this is some kind of security feature, as it also censors the docstring. However, I could not find anything about this feature. Unfortunately, it works incorrectly for f-strings.

asottile commented 4 months ago

use 3.12+ in older versions python does not tokenize fstring internals

hwalinga commented 4 months ago

@asottile Can we disable this censoring behavior as a workaround for older versions of Python?

asottile commented 4 months ago

it would not help like you think it would