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

KeyError while linting black's blib2to3/pygram.py #5172

Closed
Pierre-Sassoulas opened this issue Oct 17, 2021 · 4 comments
Closed

KeyError while linting black's blib2to3/pygram.py #5172

Pierre-Sassoulas opened this issue Oct 17, 2021 · 4 comments
Labels
Bug 🪲 Crash 💥 A bug that makes pylint crash Duplicate 🐫 Duplicate of an already existing issue
Milestone

Comments

@Pierre-Sassoulas
Copy link
Member

Pierre-Sassoulas commented Oct 17, 2021

Bug description

While parsing https://github.com/psf/black/blob/main/src/blib2to3/pygram.py getting an exception on node <Name.python_grammar l.175 at 0x7ff390d60c40>

pylint crashed with a KeyError and with the following stacktrace:

Traceback (most recent call last):
  File "/home/pierre/pylint/pylint/lint/pylinter.py", line 1028, in _check_files
    self._check_file(get_ast, check_astroid_module, file)
  File "/home/pierre/pylint/pylint/lint/pylinter.py", line 1063, in _check_file
    check_astroid_module(ast_node)
  File "/home/pierre/pylint/pylint/lint/pylinter.py", line 1199, in check_astroid_module
    retval = self._check_astroid_module(
  File "/home/pierre/pylint/pylint/lint/pylinter.py", line 1246, in _check_astroid_module
    walker.walk(node)
  File "/home/pierre/pylint/pylint/utils/ast_walker.py", line 78, in walk
    self.walk(child)
  File "/home/pierre/pylint/pylint/utils/ast_walker.py", line 78, in walk
    self.walk(child)
  File "/home/pierre/pylint/pylint/utils/ast_walker.py", line 78, in walk
    self.walk(child)
  [Previous line repeated 1 more time]
  File "/home/pierre/pylint/pylint/utils/ast_walker.py", line 75, in walk
    callback(astroid)
  File "/home/pierre/pylint/pylint/checkers/variables.py", line 1189, in visit_name
    elif self._is_only_type_assignment(node, name, defstmt):
  File "/home/pierre/pylint/pylint/checkers/variables.py", line 1560, in _is_only_type_assignment
    for ref_node in node.scope().locals[name][1:]:
KeyError: 'python_grammar'

Command used

pylint black/src/blib2to3/pygram.py

Pylint output

************* Module blib2to3.pygram
.pylint_primer_tests/black/src/blib2to3/pygram.py:24:0: R0205: Class 'Symbols' inherits from object, can be safely removed from bases in python3 (useless-object-inheritance)
.pylint_primer_tests/black/src/blib2to3/pygram.py:158:4: W0603: Using the global statement (global-statement)
.pylint_primer_tests/black/src/blib2to3/pygram.py:159:4: W0603: Using the global statement (global-statement)
.pylint_primer_tests/black/src/blib2to3/pygram.py:160:4: W0603: Using the global statement (global-statement)
.pylint_primer_tests/black/src/blib2to3/pygram.py:161:4: W0603: Using the global statement (global-statement)
.pylint_primer_tests/black/src/blib2to3/pygram.py:162:4: W0603: Using the global statement (global-statement)
.pylint_primer_tests/black/src/blib2to3/pygram.py:163:4: W0603: Using the global statement (global-statement)
.pylint_primer_tests/black/src/blib2to3/pygram.py:164:4: W0603: Using the global statement (global-statement)
Exception on node <Name.python_grammar l.175 at 0x7ff390d60c40> in file '/home/pierre/pylint/.pylint_primer_tests/black/src/blib2to3/pygram.py'
Traceback (most recent call last):
  File "/home/pierre/pylint/pylint/utils/ast_walker.py", line 75, in walk
    callback(astroid)
  File "/home/pierre/pylint/pylint/checkers/variables.py", line 1189, in visit_name
    elif self._is_only_type_assignment(node, name, defstmt):
  File "/home/pierre/pylint/pylint/checkers/variables.py", line 1560, in _is_only_type_assignment
    for ref_node in node.scope().locals[name][1:]:
KeyError: 'python_grammar'
.pylint_primer_tests/black/src/blib2to3/pygram.py:1:0: F0001: Fatal error while checking '.pylint_primer_tests/black/src/blib2to3/pygram.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/pierre/.cache/pylint/pylint-crash-2021-10-17-15.txt'. (fatal)

Expected behavior

Pylint should handle the case where the name does not exists without crash.

Pylint version

pylint 2.11.2-dev0
astroid 2.8.3
Python 3.8.10 (default, Sep 28 2021, 16:10:42) 
[GCC 9.3.0]
@cdce8p
Copy link
Member

cdce8p commented Oct 17, 2021

Might be related to #5162 although I'm not sure if it's a duplicate or another issue.

@cdce8p
Copy link
Member

cdce8p commented Oct 17, 2021

/CC: @DanielNoord

@Pierre-Sassoulas
Copy link
Member Author

Yeah sorry, it's a duplicate clearly.

@cdce8p
Copy link
Member

cdce8p commented Oct 17, 2021

Yeah sorry, it's a duplicate clearly.

Not from the initial report. However I mentioned it in a comment without know about it 😅 #5162 (comment)
Let's close this one and continue to track it in #5162

@cdce8p cdce8p closed this as completed Oct 17, 2021
@cdce8p cdce8p added the Duplicate 🐫 Duplicate of an already existing issue label Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Crash 💥 A bug that makes pylint crash Duplicate 🐫 Duplicate of an already existing issue
Projects
None yet
Development

No branches or pull requests

2 participants