pylint-bot / pylint-unofficial

UNOFFICIAL playground for pylint github migration
0 stars 0 forks source link

Pylint crashes on namedtuple attribute references #93

Closed pylint-bot closed 8 years ago

pylint-bot commented 11 years ago

Originally reported by: Grzegorz Niewisiewicz (BitBucket: grn)


pylint crashes on code that uses attributes of a namedtuple.

To reproduce do the following:

  1. clone the pylint repository with hg clone https://bitbucket.org/logilab/pylint
  2. create and activate a temporary virtual environment
  3. do cd pylint and python setup.py develop
  4. write the content below to test.py
#!python

from collections import namedtuple

Person = namedtuple('Person', ['name', 'email'])
print Person('John', 'john@localhost.localdomain').name
  1. run PYTHONPATH=.. pylint test.py.

It produces the following output:

No config file found, using default configuration
************* Module pylint.test
C:  1, 0: Missing module docstring (missing-docstring)
Traceback (most recent call last):
  File "/home/grn/.virtualenvs/60e1277463232258/bin/pylint", line 7, in <module>
    execfile(__file__)
  File "/home/grn/pylint/bin/pylint", line 3, in <module>
    run_pylint()
  File "/home/grn/pylint/__init__.py", line 21, in run_pylint
    Run(sys.argv[1:])
  File "/home/grn/pylint/lint.py", line 1010, in __init__
    linter.check(args)
  File "/home/grn/pylint/lint.py", line 599, in check
    self.check_astroid_module(astroid, walker, rawcheckers, tokencheckers)
  File "/home/grn/pylint/lint.py", line 685, in check_astroid_module
    walker.walk(astroid)
  File "/home/grn/pylint/utils.py", line 670, in walk
    self.walk(child)
  File "/home/grn/pylint/utils.py", line 670, in walk
    self.walk(child)
  File "/home/grn/pylint/utils.py", line 667, in walk
    cb(astroid)
  File "/home/grn/pylint/checkers/typecheck.py", line 174, in visit_getattr
    if is_super(owner) or getattr(owner, 'type', None) == 'metaclass':
  File "/home/grn/.virtualenvs/60e1277463232258/local/lib/python2.7/site-packages/astroid-1.0.0-py2.7.egg/astroid/bases.py", line 51, in __getattr__
    return getattr(self._proxied, name)
  File "/home/grn/.virtualenvs/60e1277463232258/local/lib/python2.7/site-packages/astroid-1.0.0-py2.7.egg/astroid/scoped_nodes.py", line 680, in _class_type
    for base in klass.ancestors(recurs=False):
  File "/home/grn/.virtualenvs/60e1277463232258/local/lib/python2.7/site-packages/astroid-1.0.0-py2.7.egg/astroid/scoped_nodes.py", line 801, in ancestors
    for baseobj in stmt.infer(context):
TypeError: unbound method infer() must be called with Tuple instance as first argument (got InferenceContext instance instead)

I expect it not to crash in this case.


pylint-bot commented 11 years ago

Original comment by Buck Evan (BitBucket: bukzor, GitHub: @bukzor?):


I'm getting this as well. This blocks us from using the current pylint.

pylint-bot commented 11 years ago

Original comment by Buck Evan (BitBucket: bukzor, GitHub: @bukzor?):


I believe this change fixes this error, but it needs released on pypi:

https://bitbucket.org/logilab/astroid/commits/5ed6266cab789bc89d882444c938f03953491496

pylint-bot commented 11 years ago

Original comment by Buck Evan (BitBucket: bukzor, GitHub: @bukzor?):


I've issued a pull request to add a regression test for this issue: https://bitbucket.org/logilab/pylint/pull-request/67/a-regression-test-for-namedtuple/diff

The test fails under current pyPI astroid (1.0.0), but passes under hg tip astroid (9cf54b49a2d4). I've opened an issue against astroid to get the necessary fix pushed to pyPI, which will finally close this issue, here: https://bitbucket.org/logilab/astroid/issue/6/please-update-pypi

pylint-bot commented 10 years ago

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


fixed by astroid 1.0.1