pylint 支持 Python 3.10.2

pylint support for Python 3.10.2

pylint 在我将 python 从 3.6.7 更新到 3.10.2 后抛出一个 AttributeError。它在 3.6.7 中运行良好。

Traceback (most recent call last):
  File "/home/yehui/Project/CleanCodeInPython/venv/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/home/yehui/Project/CleanCodeInPython/venv/lib/python3.10/site-packages/pylint/__init__.py", line 19, in run_pylint
    Run(sys.argv[1:])
  File "/home/yehui/Project/CleanCodeInPython/venv/lib/python3.10/site-packages/pylint/lint.py", line 1313, in __init__
    linter.load_default_plugins()
  File "/home/yehui/Project/CleanCodeInPython/venv/lib/python3.10/site-packages/pylint/lint.py", line 504, in load_default_plugins
    checkers.initialize(self)
  File "/home/yehui/Project/CleanCodeInPython/venv/lib/python3.10/site-packages/pylint/checkers/__init__.py", line 122, in initialize
    register_plugins(linter, __path__[0])
  File "/home/yehui/Project/CleanCodeInPython/venv/lib/python3.10/site-packages/pylint/utils.py", line 1181, in register_plugins
    module = modutils.load_module_from_file(join(directory, filename))
  File "/home/yehui/Project/CleanCodeInPython/venv/lib/python3.10/site-packages/astroid/modutils.py", line 258, in load_module_from_file
    return load_module_from_modpath(modpath)
  File "/home/yehui/Project/CleanCodeInPython/venv/lib/python3.10/site-packages/astroid/modutils.py", line 243, in load_module_from_modpath
    return load_module_from_name(".".join(parts))
  File "/home/yehui/Project/CleanCodeInPython/venv/lib/python3.10/site-packages/astroid/modutils.py", line 228, in load_module_from_name
    return importlib.import_module(dotted_name)
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/yehui/Project/CleanCodeInPython/venv/lib/python3.10/site-packages/pylint/checkers/imports.py", line 41, in <module>
    import isort
  File "/home/yehui/Project/CleanCodeInPython/venv/lib/python3.10/site-packages/isort/__init__.py", line 25, in <module>
    from . import settings  # noqa: F401
  File "/home/yehui/Project/CleanCodeInPython/venv/lib/python3.10/site-packages/isort/settings.py", line 34, in <module>
    from .pie_slice import itemsview, lru_cache, native_str
  File "/home/yehui/Project/CleanCodeInPython/venv/lib/python3.10/site-packages/isort/pie_slice.py", line 362, in <module>
    class OrderedSet(collections.MutableSet):
AttributeError: module 'collections' has no attribute 'MutableSet'

还有其他人遇到过这个问题吗?我的 pylint 是 2.12.2

编辑:如回答所述。更新pylint后我没有更新isort。 isort更新后应该没问题

实际错误似乎发生在 isort,您介意升级 isort 版本吗? (pip install isort -U) pylint 与各种 isort 版本兼容。其中一些 isort 版本可能与 python 3.10 不兼容(在这种情况下,isort 最初与 pylint 一起安装用于 python 3.6),当您升级 pylint 时,它可能不会自动升级 isort .