pylint-dev / pylint

It's not just a linter that annoys you!
https://pylint.readthedocs.io/en/latest/
GNU General Public License v2.0
5.31k stars 1.13k forks source link

namedtuple subclassing crashes pylint #65

Closed pylint-bot closed 8 years ago

pylint-bot commented 11 years ago

Originally reported by: Antony Lee (BitBucket: anntzer, GitHub: @anntzer?)


The following pattern crashes pylint 1.0.0:

#!python

from collections import namedtuple
class T(namedtuple("_T", "x")): pass # usually define methods there

with the following traceback:

Traceback (most recent call last):
  File "/usr/bin/pylint", line 3, in <module>
    run_pylint()
  File "/usr/lib/python3.3/site-packages/pylint/__init__.py", line 21, in run_pylint
    Run(sys.argv[1:])
  File "/usr/lib/python3.3/site-packages/pylint/lint.py", line 1010, in __init__
    linter.check(args)
  File "/usr/lib/python3.3/site-packages/pylint/lint.py", line 599, in check
    self.check_astroid_module(astroid, walker, rawcheckers, tokencheckers)
  File "/usr/lib/python3.3/site-packages/pylint/lint.py", line 685, in check_astroid_module
    walker.walk(astroid)
  File "/usr/lib/python3.3/site-packages/pylint/utils.py", line 662, in walk
    self.walk(child)
  File "/usr/lib/python3.3/site-packages/pylint/utils.py", line 659, in walk
    cb(astroid)
  File "/usr/lib/python3.3/site-packages/pylint/checkers/classes.py", line 219, in visit_class
    self._check_bases_classes(node)
  File "/usr/lib/python3.3/site-packages/pylint/checkers/classes.py", line 514, in _check_bases_classes
    if class_is_abstract(node):
  File "/usr/lib/python3.3/site-packages/pylint/checkers/classes.py", line 32, in class_is_abstract
    for method in node.methods():
  File "/usr/lib/python3.3/site-packages/astroid/scoped_nodes.py", line 958, in methods
    for astroid in chain(iter((self,)), self.ancestors()):
  File "/usr/lib/python3.3/site-packages/astroid/scoped_nodes.py", line 810, in ancestors
    for grandpa in baseobj.ancestors(True, context):
  File "/usr/lib/python3.3/site-packages/astroid/scoped_nodes.py", line 801, in ancestors
    for baseobj in stmt.infer(context):
  File "/usr/lib/python3.3/site-packages/astroid/bases.py", line 368, in infer
    if self._explicit_inference is not None:
AttributeError: 'InferenceContext' object has no attribute '_explicit_inference'

pylint-bot commented 11 years ago

Original comment by Sylvain Thénault (BitBucket: sthenault, GitHub: @sthenault?):


This is probably the python3 version of https://bitbucket.org/logilab/astroid/issue/3/error-after-upgrade-to-pylint-10.

Could you try using the astroid mercurial tip to ensure it fixes the pb ?

pylint-bot commented 11 years ago

Original comment by Sylvain Thénault (BitBucket: sthenault, GitHub: @sthenault?):


should be fixed by astroid tip

pylint-bot commented 11 years ago

Original comment by Antony Lee (BitBucket: anntzer, GitHub: @anntzer?):


Yes, this works, thanks.

pylint-bot commented 10 years ago

Original comment by Antony Lee (BitBucket: anntzer, GitHub: @anntzer?):


A slight variant of this still crashes pylint (1.3.1):

#!python
from collections import namedtuple
class C(namedtuple("C", "foo bar")):
    def __str__(self):
        return "{0.foo}: {0.bar}".format(self)
pylint-bot commented 10 years ago

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):


Could you open another issue with this crash, please?