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

pylint crashes when "with ... as" is used in an enum #3365

Closed
martimlobao opened this issue Jan 24, 2020 · 0 comments
Closed

pylint crashes when "with ... as" is used in an enum #3365

martimlobao opened this issue Jan 24, 2020 · 0 comments

Comments

@martimlobao
Copy link

martimlobao commented Jan 24, 2020

Steps to reproduce

  1. Create test.py:
import enum

class Error(enum.Enum):
    Foo = "foo"
    Bar = "bar"
    with "error" as err:
        pass
  1. Run pylint test.py.

Current behavior

An IndexError exception is raised and pylint crashes:

$ pylint test.py
************* Module test
test.py:1:0: C0114: Missing module docstring (missing-module-docstring)
test.py:4:0: C0115: Missing class docstring (missing-class-docstring)
Traceback (most recent call last):
  File "/Users/me/.pyenv/versions/clean/bin/pylint", line 11, in <module>
    sys.exit(run_pylint())
  File "/Users/me/.pyenv/versions/3.6.6/envs/clean/lib/python3.6/site-packages/pylint/__init__.py", line 23, in run_pylint
    PylintRun(sys.argv[1:])
  File "/Users/me/.pyenv/versions/3.6.6/envs/clean/lib/python3.6/site-packages/pylint/lint.py", line 1731, in __init__
    linter.check(args)
  File "/Users/me/.pyenv/versions/3.6.6/envs/clean/lib/python3.6/site-packages/pylint/lint.py", line 1004, in check
    self._do_check(files_or_modules)
  File "/Users/me/.pyenv/versions/3.6.6/envs/clean/lib/python3.6/site-packages/pylint/lint.py", line 1165, in _do_check
    self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
  File "/Users/me/.pyenv/versions/3.6.6/envs/clean/lib/python3.6/site-packages/pylint/lint.py", line 1252, in check_astroid_module
    walker.walk(ast_node)
  File "/Users/me/.pyenv/versions/3.6.6/envs/clean/lib/python3.6/site-packages/pylint/utils/ast_walker.py", line 77, in walk
    self.walk(child)
  File "/Users/me/.pyenv/versions/3.6.6/envs/clean/lib/python3.6/site-packages/pylint/utils/ast_walker.py", line 74, in walk
    callback(astroid)
  File "/Users/me/.pyenv/versions/3.6.6/envs/clean/lib/python3.6/site-packages/pylint/checkers/classes.py", line 755, in visit_classdef
    self._check_bases_classes(node)
  File "/Users/me/.pyenv/versions/3.6.6/envs/clean/lib/python3.6/site-packages/pylint/checkers/classes.py", line 1537, in _check_bases_classes
    if class_is_abstract(node):
  File "/Users/me/.pyenv/versions/3.6.6/envs/clean/lib/python3.6/site-packages/pylint/checkers/utils.py", line 929, in class_is_abstract
    for method in node.methods():
  File "/Users/me/.pyenv/versions/3.6.6/envs/clean/lib/python3.6/site-packages/astroid/scoped_nodes.py", line 2547, in methods
    for meth in astroid.mymethods():
  File "/Users/me/.pyenv/versions/3.6.6/envs/clean/lib/python3.6/site-packages/astroid/scoped_nodes.py", line 2559, in mymethods
    for member in self.values():
  File "/Users/me/.pyenv/versions/3.6.6/envs/clean/lib/python3.6/site-packages/astroid/scoped_nodes.py", line 276, in values
    return [self[key] for key in self.keys()]
  File "/Users/me/.pyenv/versions/3.6.6/envs/clean/lib/python3.6/site-packages/astroid/scoped_nodes.py", line 276, in <listcomp>
    return [self[key] for key in self.keys()]
  File "/Users/me/.pyenv/versions/3.6.6/envs/clean/lib/python3.6/site-packages/astroid/scoped_nodes.py", line 252, in __getitem__
    return self.locals[item][0]
IndexError: list index out of range

Expected behavior

pylint should not crash.

pylint --version output

astroid 2.3.3
Python 3.6.6 (default, Feb 12 2019, 20:41:17) 
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.10.44.4)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant