Skip to content

Crash "Fatal error while checking" with metaclass #8698

@bersbersbers

Description

@bersbersbers

Bug description

When parsing the following file:

"""Fatal error while checking."""
class Meta(type(object), type(object)):
    pass

class Class(metaclass=Meta):
    pass

pylint crashed with a AstroidError and with the following stacktrace:

Traceback (most recent call last):
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\pylint\lint\pylinter.py", line 811, in _lint_file
    check_astroid_module(module)
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\pylint\lint\pylinter.py", line 1085, in check_astroid_module
    retval = self._check_astroid_module(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\pylint\lint\pylinter.py", line 1135, in _check_astroid_module
    walker.walk(node)
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\pylint\utils\ast_walker.py", line 94, in walk
    self.walk(child)
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\pylint\utils\ast_walker.py", line 91, in walk
    callback(astroid)
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\pylint\checkers\typecheck.py", line 1040, in visit_classdef
    if _is_invalid_metaclass(metaclass):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\pylint\checkers\typecheck.py", line 748, in _is_invalid_metaclass
    mro = metaclass.mro()
          ^^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\astroid\nodes\scoped_nodes\scoped_nodes.py", line 3066, in mro
    return self._compute_mro(context=context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\astroid\nodes\scoped_nodes\scoped_nodes.py", line 3054, in _compute_mro
    unmerged_mro = list(clean_duplicates_mro(unmerged_mro, self, context))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\astroid\nodes\scoped_nodes\scoped_nodes.py", line 155, in clean_duplicates_mro
    raise DuplicateBasesError(
astroid.exceptions.DuplicateBasesError: Duplicates found in MROs (Meta), (type, object), (type, object), (type, type) for <ClassDef.Meta l.2 at 0x26ca8902bd0>.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\pylint\lint\pylinter.py", line 775, in _lint_files
    self._lint_file(fileitem, module, check_astroid_module)
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\pylint\lint\pylinter.py", line 813, in _lint_file
    raise astroid.AstroidError from e
astroid.exceptions.AstroidError

Configuration

No response

Command used

pylint bug.py

Pylint output

************* Module bug
bug.py:2:0: C0115: Missing class docstring (missing-class-docstring)
bug.py:2:0: E0241: Duplicate bases for class 'Meta' (duplicate-bases)
bug.py:5:0: C0115: Missing class docstring (missing-class-docstring)
Exception on node <ClassDef.Class l.5 at 0x26ca8903410> in file 'C:\Code\Bug\bug.py'
Traceback (most recent call last):
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\pylint\utils\ast_walker.py", line 91, in walk
    callback(astroid)
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\pylint\checkers\typecheck.py", line 1040, in visit_classdef
    if _is_invalid_metaclass(metaclass):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\pylint\checkers\typecheck.py", line 748, in _is_invalid_metaclass
    mro = metaclass.mro()
          ^^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\astroid\nodes\scoped_nodes\scoped_nodes.py", line 3066, in mro
    return self._compute_mro(context=context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\astroid\nodes\scoped_nodes\scoped_nodes.py", line 3054, in _compute_mro
    unmerged_mro = list(clean_duplicates_mro(unmerged_mro, self, context))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\bers\.pyenv-win-venv\envs\project_3.11\Lib\site-packages\astroid\nodes\scoped_nodes\scoped_nodes.py", line 155, in clean_duplicates_mro
    raise DuplicateBasesError(
astroid.exceptions.DuplicateBasesError: Duplicates found in MROs (Meta), (type, object), (type, object), (type, type) for <ClassDef.Meta l.2 at 0x26ca8902bd0>.
bug.py:1:0: F0002: bug.py: Fatal error while checking 'bug.py'. Please open an issue in our bug tracker so we address this. There is a pre-filled template that you can use in 'C:\Users\bers\AppData\Local\pylint\pylint\Cache\pylint-crash-2023-05-18-09-05-35.txt'. (astroid-error)

------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 7.14/10, -7.14)

Expected behavior

I have no idea if the code examples makes any sense, but pylint should not crash.

Pylint version

pylint 2.17.4
astroid 2.15.5
Python 3.11.3 (tags/v3.11.3:f3909b8, Apr  4 2023, 23:49:59) [MSC v.1934 64 bit (AMD64)]

OS / Environment

Windows 10 21H2

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Crash 💥A bug that makes pylint crashNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions