Skip to content

AttributeError: type object 'FlakesChecker' has no attribute 'builtIns' with --builtins after upgrading to 7.4.0 #2056

Description

@AhmadMasry

how did you install flake8?

$ venv/bin/pip install flake8       
Collecting flake8
  Using cached flake8-7.4.0-py2.py3-none-any.whl.metadata (3.8 kB)
Collecting mccabe<0.8.0,>=0.7.0 (from flake8)
  Using cached mccabe-0.7.0-py2.py3-none-any.whl.metadata (5.0 kB)
Collecting pycodestyle<2.16.0,>=2.15.0 (from flake8)
  Using cached pycodestyle-2.15.0-py2.py3-none-any.whl.metadata (4.5 kB)
Collecting pyflakes<4.1.0,>=4.0.0 (from flake8)
  Using cached pyflakes-4.0.0-py2.py3-none-any.whl.metadata (3.5 kB)
Using cached flake8-7.4.0-py2.py3-none-any.whl (57 kB)
Using cached mccabe-0.7.0-py2.py3-none-any.whl (7.3 kB)
Using cached pycodestyle-2.15.0-py2.py3-none-any.whl (31 kB)
Using cached pyflakes-4.0.0-py2.py3-none-any.whl (65 kB)
Installing collected packages: pyflakes, pycodestyle, mccabe, flake8
Successfully installed flake8-7.4.0 mccabe-0.7.0 pycodestyle-2.15.0 pyflakes-4.0.0

unmodified output of flake8 --bug-report

{
  "platform": {
    "python_implementation": "CPython",
    "python_version": "3.12.8",
    "system": "Darwin"
  },
  "plugins": [
    {
      "plugin": "mccabe",
      "version": "0.7.0"
    },
    {
      "plugin": "pycodestyle",
      "version": "2.15.0"
    },
    {
      "plugin": "pyflakes",
      "version": "4.0.0"
    }
  ],
  "version": "7.4.0"
}

describe the problem

what I expected to happen

--builtins (or builtins = in a config file) adds names to the set of builtins, as in 7.3.0, and no F821 is reported for them.

sample code

print(_("x"))

commands ran

$ flake8 --builtins=_ --select E9,F82 .

Traceback (most recent call last):
  File "venv/lib/python3.12/site-packages/flake8/options/parse_args.py", line 62, in parse_args
    parse_options(
TypeError: FlakesChecker.parse_options() takes 2 positional arguments but 4 were given

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "venv/bin/flake8", line 10, in <module>
    sys.exit(main())
              ^^^^^^
  File "venv/lib/python3.12/site-packages/flake8/main/cli.py", line 23, in main
    app.run(argv)
  File "venv/lib/python3.12/site-packages/flake8/main/application.py", line 198, in run
    self._run(argv)
  File "venv/lib/python3.12/site-packages/flake8/main/application.py", line 186, in _run
    self.initialize(argv)
  File "venv/lib/python3.12/site-packages/flake8/main/application.py", line 165, in initialize
    self.plugins, self.options = parse_args(argv)
                                  ^^^^^^^^^^^^^^^^
  File "venv/lib/python3.12/site-packages/flake8/options/parse_args.py", line 68, in parse_args
    parse_options(opts)
  File "venv/lib/python3.12/site-packages/flake8/plugins/pyflakes.py", line 102, in parse_options
    cls.builtIns = cls.builtIns.union(options.builtins)
                    ^^^^^^^^^^^^
AttributeError: type object 'FlakesChecker' has no attribute 'builtIns'

We expect that either flake8 7.4.0 or pyflakes 4.0.0 is the cause of the issue, because it returned to work after we downgraded to flake8 7.3.0 or pyflakes 3.4.0

Please note that using PYFLAKES_BUILTINS=_ environment variable still works.
Is flake8 removing --builtins=_ so we migrate to the environment variable, or is there a new way to define builtins?

If there is no intention to remove the option, I suspect that the cause is in pyflakes 4.0.0 (PyCQA/pyflakes#893). It removed the Checker.builtIns class attribute. flake8's FlakesChecker.parse_options still reads and writes cls.builtIns (src/flake8/plugins/pyflakes.py#L99-L103). pyflakes supports custom builtins through the existing builtins= argument of Checker.init.

I prepared a fix in my fork, AhmadMasry@778b89d, I can open a PR if you see it fits.

Thanks in advance.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions