Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash "Fatal error while checking" with metaclass #8698

Closed
bersbersbers opened this issue May 18, 2023 · 2 comments · Fixed by #8699
Closed

Crash "Fatal error while checking" with metaclass #8698

bersbersbers opened this issue May 18, 2023 · 2 comments · Fixed by #8699
Labels
Crash 💥 A bug that makes pylint crash Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Milestone

Comments

@bersbersbers
Copy link

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

@bersbersbers bersbersbers added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label May 18, 2023
@bersbersbers
Copy link
Author

Probably related:

When parsing the following file:

from pathlib import Path
from typing import Protocol

class Proto(Protocol):
    ...

class Meta(type(Path), type(Proto)):
    pass

class Class(Path, Proto, 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 3056, in _compute_mro
    return _c3_merge(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 96, in _c3_merge
    raise InconsistentMroError(
astroid.exceptions.InconsistentMroError: Cannot create a consistent method resolution order for MROs (type, object), (_ProtocolMeta, ABCMeta, type, object), (type, _ProtocolMeta) of class <ClassDef.Meta l.9 at 0x21e4765e790>.

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

@Pierre-Sassoulas Pierre-Sassoulas added Crash 💥 A bug that makes pylint crash Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels May 18, 2023
@Pierre-Sassoulas
Copy link
Member

Thank you for opening the bug, I can reproduce on main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Crash 💥 A bug that makes pylint crash Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants