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 invalid enum value: 6 when importing cairo #6371

Closed
senier opened this issue Apr 17, 2022 · 3 comments · Fixed by pylint-dev/astroid#1518
Closed

Crash invalid enum value: 6 when importing cairo #6371

senier opened this issue Apr 17, 2022 · 3 comments · Fixed by pylint-dev/astroid#1518
Labels
Crash 💥 A bug that makes pylint crash Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) Needs astroid update Needs an astroid update (probably a release too) before being mergable
Milestone

Comments

@senier
Copy link

senier commented Apr 17, 2022

Bug description

When parsing the following file:

import gi
gi.require_version("cairo", "1.0")
from gi.repository import cairo  # noqa: E402

pylint crashed with a ValueError and with the following stacktrace:

Traceback (most recent call last):
  File "/home/user/tmp/pylint/.venv/lib/python3.9/site-packages/astroid/manager.py", line 145, in ast_from_module_name
    found_spec = self.file_from_module_name(modname, context_file)
  File "/home/user/tmp/pylint/.venv/lib/python3.9/site-packages/astroid/manager.py", line 246, in file_from_module_name
    raise value.with_traceback(None)
astroid.exceptions.AstroidImportError: Failed to import module gi.repository.cairo with error:
No module named gi.repository.cairo.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/tmp/pylint/.venv/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1111, in _check_files
    self._check_file(get_ast, check_astroid_module, file)
  File "/home/user/tmp/pylint/.venv/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1146, in _check_file
    check_astroid_module(ast_node)
  File "/home/user/tmp/pylint/.venv/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1298, in check_astroid_module
    retval = self._check_astroid_module(
  File "/home/user/tmp/pylint/.venv/lib/python3.9/site-packages/pylint/lint/pylinter.py", line 1345, in _check_astroid_module
    walker.walk(node)
  File "/home/user/tmp/pylint/.venv/lib/python3.9/site-packages/pylint/utils/ast_walker.py", line 76, in walk
    self.walk(child)
  File "/home/user/tmp/pylint/.venv/lib/python3.9/site-packages/pylint/utils/ast_walker.py", line 73, in walk
    callback(astroid)
  File "/home/user/tmp/pylint/.venv/lib/python3.9/site-packages/pylint/checkers/variables.py", line 1752, in visit_importfrom
    self._check_module_attrs(node, module, name.split("."))
  File "/home/user/tmp/pylint/.venv/lib/python3.9/site-packages/pylint/checkers/variables.py", line 2622, in _check_module_attrs
    module = next(module.getattr(name)[0].infer())
  File "/home/user/tmp/pylint/.venv/lib/python3.9/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 412, in getattr
    result = [self.import_module(name, relative_only=True)]
  File "/home/user/tmp/pylint/.venv/lib/python3.9/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 527, in import_module
    return AstroidManager().ast_from_module_name(absmodname)
  File "/home/user/tmp/pylint/.venv/lib/python3.9/site-packages/astroid/manager.py", line 193, in ast_from_module_name
    return hook(modname)
  File "/home/user/tmp/pylint/.venv/lib/python3.9/site-packages/astroid/brain/brain_gi.py", line 193, in _import_gi_module
    modcode += _gi_build_stub(sys.modules[m])
  File "/home/user/tmp/pylint/.venv/lib/python3.9/site-packages/astroid/brain/brain_gi.py", line 76, in _gi_build_stub
    obj = getattr(parent, name)
  File "/home/user/tmp/pylint/.venv/lib/python3.9/site-packages/gi/module.py", line 155, in __getattr__
    setattr(wrapper, value_name, wrapper(value_info.get_value()))
ValueError: invalid enum value: 6

Configuration

No response

Command used

pylint issue.py

Pylint output

Traceback (most recent call last):
  File "/home/user/tmp/pylint/.venv/lib/python3.9/site-packages/astroid/manager.py", line 145, in ast_from_module_name
    found_spec = self.file_from_module_name(modname, context_file)
  File "/home/user/tmp/pylint/.venv/lib/python3.9/site-packages/astroid/manager.py", line 246, in file_from_module_name
    raise value.with_traceback(None)
astroid.exceptions.AstroidImportError: Failed to import module gi.repository.cairo with error:
No module named gi.repository.cairo.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/tmp/pylint/.venv/lib/python3.9/site-packages/pylint/utils/ast_walker.py", line 73, in walk
    callback(astroid)
  File "/home/user/tmp/pylint/.venv/lib/python3.9/site-packages/pylint/checkers/variables.py", line 1752, in visit_importfrom
    self._check_module_attrs(node, module, name.split("."))
  File "/home/user/tmp/pylint/.venv/lib/python3.9/site-packages/pylint/checkers/variables.py", line 2622, in _check_module_attrs
    module = next(module.getattr(name)[0].infer())
  File "/home/user/tmp/pylint/.venv/lib/python3.9/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 412, in getattr
    result = [self.import_module(name, relative_only=True)]
  File "/home/user/tmp/pylint/.venv/lib/python3.9/site-packages/astroid/nodes/scoped_nodes/scoped_nodes.py", line 527, in import_module
    return AstroidManager().ast_from_module_name(absmodname)
  File "/home/user/tmp/pylint/.venv/lib/python3.9/site-packages/astroid/manager.py", line 193, in ast_from_module_name
    return hook(modname)
  File "/home/user/tmp/pylint/.venv/lib/python3.9/site-packages/astroid/brain/brain_gi.py", line 193, in _import_gi_module
    modcode += _gi_build_stub(sys.modules[m])
  File "/home/user/tmp/pylint/.venv/lib/python3.9/site-packages/astroid/brain/brain_gi.py", line 76, in _gi_build_stub
    obj = getattr(parent, name)
  File "/home/user/tmp/pylint/.venv/lib/python3.9/site-packages/gi/module.py", line 155, in __getattr__
    setattr(wrapper, value_name, wrapper(value_info.get_value()))
ValueError: invalid enum value: 6
************* Module issue
issue.py:1:0: C0114: Missing module docstring (missing-module-docstring)
Exception on node <ImportFrom l.7 at 0x7fd8f3d00ca0> in file '/home/user/tmp/pylint/issue.py'
issue.py:1:0: F0001: Fatal error while checking 'issue.py'. Please open an issue in our bug tracker so we address this. There is a pre-filled template that you can use in '/home/user/.cache/pylint/pylint-crash-2022-04-17-23.txt'. (fatal)

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

Expected behavior

Do not crash. Check the file as usual and report issue through error messages.

Pylint version

$ pylint --version
pylint 2.13.5
astroid 2.11.2
Python 3.9.12 (main, Mar 24 2022, 13:02:21) 
[GCC 11.2.0]

OS / Environment

Debian Linux, x86_64

Additional dependencies

$ pip freeze
astroid==2.11.2
dill==0.3.4
isort==5.10.1
lazy-object-proxy==1.7.1
mccabe==0.7.0
platformdirs==2.5.1
pycairo==1.21.0
PyGObject==3.40.1
pylint==2.13.5
tomli==2.0.1
typing_extensions==4.1.1
wrapt==1.14.0

@senier senier added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Apr 17, 2022
@jacobtylerwalls
Copy link
Member

Thanks for the report. Probably as simple as reverting pylint-dev/astroid@8590532.

@jacobtylerwalls jacobtylerwalls added Needs astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) Crash 💥 A bug that makes pylint crash and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Apr 17, 2022
@jacobtylerwalls jacobtylerwalls modified the milestones: 2.13.6, 2.14.0 Apr 17, 2022
@jacobtylerwalls jacobtylerwalls added the Needs astroid update Needs an astroid update (probably a release too) before being mergable label Apr 17, 2022
@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 2.14.0, 2.13.6 Apr 18, 2022
@jacobtylerwalls
Copy link
Member

Ah, are we going to require the astroid patch release in 2.13.6? I was thinking @DanielNoord just wanted the astroid patch release for the 2.14 pre-release.

@Pierre-Sassoulas
Copy link
Member

We can backport the astroid upgrade in 2.13.

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 astroid Brain 🧠 Needs a brain tip in astroid (then an astroid upgrade) Needs astroid update Needs an astroid update (probably a release too) before being mergable
Projects
None yet
3 participants