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

AstroidSyntaxError when namedtuple has invalid label #3549

Closed
rjthomson opened this issue Apr 30, 2020 · 1 comment
Closed

AstroidSyntaxError when namedtuple has invalid label #3549

rjthomson opened this issue Apr 30, 2020 · 1 comment
Labels

Comments

@rjthomson
Copy link

Steps to reproduce

import collections
a = collections.namedtuple( 'a', ['b c'] )
x = a(b=123, c=456)

Current behavior

% pylint error.py
Using config file /etc/pylintrc
Traceback (most recent call last):
File "/usr/bin/pylint", line 11, in
load_entry_point('pylint==1.9.2', 'console_scripts', 'pylint')()
File "/usr/lib/python2.7/site-packages/pylint/init.py", line 16, in run_pylint
Run(sys.argv[1:])
File "/usr/lib/python2.7/site-packages/pylint/lint.py", line 1347, in init
linter.check(args)
File "/usr/lib/python2.7/site-packages/pylint/lint.py", line 768, in check
self._do_check(files_or_modules)
File "/usr/lib/python2.7/site-packages/pylint/lint.py", line 901, in _do_check
self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
File "/usr/lib/python2.7/site-packages/pylint/lint.py", line 980, in check_astroid_module
walker.walk(ast_node)
File "/usr/lib/python2.7/site-packages/pylint/utils.py", line 1014, in walk
self.walk(child)
File "/usr/lib/python2.7/site-packages/pylint/utils.py", line 1014, in walk
self.walk(child)
File "/usr/lib/python2.7/site-packages/pylint/utils.py", line 1011, in walk
cb(astroid)
File "/usr/lib/python2.7/site-packages/pylint/checkers/base.py", line 1451, in visit_assignname
if isinstance(utils.safe_infer(ass_type.value), astroid.ClassDef):
File "/usr/lib/python2.7/site-packages/backports/functools_lru_cache.py", line 137, in wrapper
result = user_function(*args, **kwds)
File "/usr/lib/python2.7/site-packages/pylint/checkers/utils.py", line 821, in safe_infer
inferit = node.infer(context=context)
File "/usr/lib/python2.7/site-packages/astroid/node_classes.py", line 295, in infer
return self._explicit_inference(self, context, **kwargs)
File "/usr/lib/python2.7/site-packages/astroid/brain/brain_namedtuple_enum.py", line 177, in infer_named_tuple
'replace_args': replace_args})
File "/usr/lib/python2.7/site-packages/astroid/builder.py", line 157, in string_build
module = self._data_build(data, modname, path)
File "/usr/lib/python2.7/site-packages/astroid/builder.py", line 187, in _data_build
source=data, modname=modname, path=path, error=exc))
File "/usr/lib/python2.7/site-packages/astroid/util.py", line 30, in reraise
six.reraise(type(exception), exception, sys.exc_info()[2])
File "/usr/lib/python2.7/site-packages/astroid/builder.py", line 183, in _data_build
node = _parse(data + '\n')
File "/usr/lib/python2.7/site-packages/astroid/builder.py", line 41, in _parse
return compile(string, "", 'exec', _ast.PyCF_ONLY_AST)
astroid.exceptions.AstroidSyntaxError: Parsing Python code failed:
invalid syntax (, line 10)

Expected behavior

No crash, and ideally report the invalid label.

pylint --version output

Using config file /etc/pylintrc
pylint 1.9.2,
astroid 1.6.1
Python 2.7.18 (default, Apr 24 2020, 12:25:53)
[GCC 6.5.0 20181026 (Red Hat 6.5.0-3)]

@PCManticore
Copy link
Contributor

Thanks, should be fixed with the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants