PyCQA/flake8

Flake8 fails to load `pyflakes` plugin due to `collections.Callable` attribute error

suhee-yoo opened this issue · 2 comments

how did you install flake8?

$ pip install flake8

unmodified output of flake8 --bug-report

Traceback (most recent call last):
  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\flake8\plugins\finder.py", line 291, in _load_plugin
    obj = plugin.entry_point.load()
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\suhee\AppData\Local\Programs\Python\Python311\Lib\importlib\metadata\__init__.py", line 202, in load 
    module = import_module(match.group('module'))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\suhee\AppData\Local\Programs\Python\Python311\Lib\importlib\__init__.py", line 126, in import_module 
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\flake8\plugins\pyflakes.py", line 10, in <module>   
    import pyflakes.checker
  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\pyflakes\checker.py", line 12, in <module>
    import doctest
  File "C:\Users\suhee\AppData\Local\Programs\Python\Python311\Lib\doctest.py", line 100, in <module>
    import pdb
  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\_pdbpp_path_hack\pdb.py", line 5, in <module>
    exec(compile(f.read(), pdb_path, 'exec'))
  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\pdb.py", line 23, in <module>
    from fancycompleter import Completer, ConfigurableClass, Color
  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\fancycompleter.py", line 7, in <module>
    import rlcompleter
  File "C:\Users\suhee\AppData\Local\Programs\Python\Python311\Lib\rlcompleter.py", line 210, in <module>
    import readline
    rl = Readline()
         ^^^^^^^^^^
  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\pyreadline\rlmain.py", line 422, in __init__
    BaseReadline.__init__(self)
  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\pyreadline\rlmain.py", line 62, in __init__
    mode.init_editing_mode(None)
  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\pyreadline\modes\emacs.py", line 633, in init_editing_mode
    self._bind_key('space',       self.self_insert)
  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\pyreadline\modes\basemode.py", line 162, in _bind_key
    if not callable(func):
           ^^^^^^^^^^^^^^
  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\pyreadline\py3k_compat.py", line 8, in callable
    return isinstance(x, collections.Callable)
                         ^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'collections' has no attribute 'Callable'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\suhee\work\PythonProject\.venv\Scripts\flake8.exe\__main__.py", line 7, in <module>
  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\flake8\main\cli.py", line 23, in main
    app.run(argv)
  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\flake8\main\application.py", line 198, in run
    self._run(argv)
  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\flake8\main\application.py", line 186, in _run
    self.initialize(argv)
  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\flake8\main\application.py", line 165, in initialize
    self.plugins, self.options = parse_args(argv)
                                 ^^^^^^^^^^^^^^^^
  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\flake8\options\parse_args.py", line 42, in parse_args
    plugins = finder.load_plugins(raw_plugins, plugin_opts)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\flake8\plugins\finder.py", line 365, in load_plugins
    return _classify_plugins(_import_plugins(plugins, opts), opts)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\flake8\plugins\finder.py", line 307, in _import_plugins
    return [_load_plugin(p) for p in plugins]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\flake8\plugins\finder.py", line 307, in <listcomp>
    return [_load_plugin(p) for p in plugins]
            ^^^^^^^^^^^^^^^
  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\flake8\plugins\finder.py", line 293, in _load_plugin
    raise FailedToLoadPlugin(plugin.package, e)
flake8.exceptions.FailedToLoadPlugin: Flake8 failed to load plugin "pyflakes" due to module 'collections' has no attribute 'Callable'.  

describe the problem

what I expected to happen

Description :

While running Flake8 in my Python project, the tool fails to load the pyflakes plugin, resulting in an AttributeError. The error message indicates that the collections module has no attribute Callable. This issue occurs when attempting to use Flake8 in a Python 3.10+ environment where collections.Callable has been deprecated and moved to collections.abc.Callable.

Steps to Reproduce:

  1. Set up a Python 3.11 virtual environment.
  2. Install Flake8 along with its dependencies.
  3. Run Flake8 on any Python project or script.

Environment:

  • OS: Windows
  • Python Version: 3.11
  • Flake8 Version:
name = "flake8"
version = "7.1.1"
description = "the modular source code checker: pep8 pyflakes and co"
optional = false
python-versions = ">=3.8.1"
files = [
    {file = "flake8-7.1.1-py2.py3-none-any.whl", hash = "sha256:597477df7860daa5aa0fdd84bf5208a043ab96b8e96ab708770ae0364dd03213"},
    {file = "flake8-7.1.1.tar.gz", hash = "sha256:049d058491e228e03e67b390f311bbf88fce2dbaa8fa673e7aea87b7198b8d38"},
]
  • pyflakes Version:
name = "pyflakes"
version = "3.2.0"
description = "passive checker of Python programs"
optional = false
python-versions = ">=3.8"
files = [
    {file = "pyflakes-3.2.0-py2.py3-none-any.whl", hash = "sha256:84b5be138a2dfbb40689ca07e2152deb896a65c3a3e24c251c5c62489568074a"},
    {file = "pyflakes-3.2.0.tar.gz", hash = "sha256:1c61603ff154621fb2a9172037d84dca3500def8c8b630657d1701f026f8af3f"},
]

Thanks

you'll notice the error comes from pyreadline which is something you installed and not part of our packaging

This seems to be coming from things in your virtual environment that you have installed:

Namely when we try to import a standard library it imports some"hack" you have which triggers the bad import. This isn't a flake8 bug

  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\_pdbpp_path_hack\pdb.py", line 5, in <module>
    exec(compile(f.read(), pdb_path, 'exec'))
  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\pdb.py", line 23, in <module>
    from fancycompleter import Completer, ConfigurableClass, Color
  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\fancycompleter.py", line 7, in <module>
    import rlcompleter
  File "C:\Users\suhee\AppData\Local\Programs\Python\Python311\Lib\rlcompleter.py", line 210, in <module>
    import readline
    rl = Readline()
         ^^^^^^^^^^
  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\pyreadline\rlmain.py", line 422, in __init__
    BaseReadline.__init__(self)
  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\pyreadline\rlmain.py", line 62, in __init__
    mode.init_editing_mode(None)
  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\pyreadline\modes\emacs.py", line 633, in init_editing_mode
    self._bind_key('space',       self.self_insert)
  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\pyreadline\modes\basemode.py", line 162, in _bind_key
    if not callable(func):
           ^^^^^^^^^^^^^^
  File "C:\Users\suhee\work\PythonProject\.venv\Lib\site-packages\pyreadline\py3k_compat.py", line 8, in callable
    return isinstance(x, collections.Callable)
                         ^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'collections' has no attribute 'Callable'