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

AttributeError: 'arg' object has no attribute 'scope' #3174

Closed
asottile opened this issue Oct 8, 2019 · 2 comments
Closed

AttributeError: 'arg' object has no attribute 'scope' #3174

asottile opened this issue Oct 8, 2019 · 2 comments

Comments

@asottile
Copy link
Contributor

asottile commented Oct 8, 2019

Steps to reproduce

here's a minimal case

class D:
    @staticmethod
    def g(
        x  # type: np.array
    ):
        pass

D.g(1)

Current behavior

$ pylint x.py --py3k
Traceback (most recent call last):
  File "/tmp/x/venv/lib/python3.6/site-packages/pylint/lint.py", line 1212, in get_ast
    return MANAGER.ast_from_file(filepath, modname, source=True)
  File "/tmp/x/venv/lib/python3.6/site-packages/astroid/manager.py", line 94, in ast_from_file
    return AstroidBuilder(self).file_build(filepath, modname)
  File "/tmp/x/venv/lib/python3.6/site-packages/astroid/builder.py", line 136, in file_build
    return self._post_build(module, encoding)
  File "/tmp/x/venv/lib/python3.6/site-packages/astroid/builder.py", line 160, in _post_build
    module = self._manager.visit_transforms(module)
  File "/tmp/x/venv/lib/python3.6/site-packages/astroid/manager.py", line 72, in visit_transforms
    return self._transform.visit(node)
  File "/tmp/x/venv/lib/python3.6/site-packages/astroid/transforms.py", line 89, in visit
    module.body = [self._visit(child) for child in module.body]
  File "/tmp/x/venv/lib/python3.6/site-packages/astroid/transforms.py", line 89, in <listcomp>
    module.body = [self._visit(child) for child in module.body]
  File "/tmp/x/venv/lib/python3.6/site-packages/astroid/transforms.py", line 54, in _visit
    visited = self._visit_generic(value)
  File "/tmp/x/venv/lib/python3.6/site-packages/astroid/transforms.py", line 61, in _visit_generic
    return [self._visit_generic(child) for child in node]
  File "/tmp/x/venv/lib/python3.6/site-packages/astroid/transforms.py", line 61, in <listcomp>
    return [self._visit_generic(child) for child in node]
  File "/tmp/x/venv/lib/python3.6/site-packages/astroid/transforms.py", line 67, in _visit_generic
    return self._visit(node)
  File "/tmp/x/venv/lib/python3.6/site-packages/astroid/transforms.py", line 54, in _visit
    visited = self._visit_generic(value)
  File "/tmp/x/venv/lib/python3.6/site-packages/astroid/transforms.py", line 67, in _visit_generic
    return self._visit(node)
  File "/tmp/x/venv/lib/python3.6/site-packages/astroid/transforms.py", line 54, in _visit
    visited = self._visit_generic(value)
  File "/tmp/x/venv/lib/python3.6/site-packages/astroid/transforms.py", line 61, in _visit_generic
    return [self._visit_generic(child) for child in node]
  File "/tmp/x/venv/lib/python3.6/site-packages/astroid/transforms.py", line 61, in <listcomp>
    return [self._visit_generic(child) for child in node]
  File "/tmp/x/venv/lib/python3.6/site-packages/astroid/transforms.py", line 67, in _visit_generic
    return self._visit(node)
  File "/tmp/x/venv/lib/python3.6/site-packages/astroid/transforms.py", line 57, in _visit
    return self._transform(node)
  File "/tmp/x/venv/lib/python3.6/site-packages/astroid/transforms.py", line 39, in _transform
    if predicate is None or predicate(node):
  File "/tmp/x/venv/lib/python3.6/site-packages/astroid/brain/brain_numpy_utils.py", line 55, in looks_like_numpy_member
    and _is_a_numpy_module(node.expr)
  File "/tmp/x/venv/lib/python3.6/site-packages/astroid/brain/brain_numpy_utils.py", line 32, in _is_a_numpy_module
    x for x in node.lookup(module_nickname)[1] if isinstance(x, astroid.Import)
  File "/tmp/x/venv/lib/python3.6/site-packages/astroid/node_classes.py", line 1061, in lookup
    return self.scope().scope_lookup(self, name)
  File "/tmp/x/venv/lib/python3.6/site-packages/astroid/node_classes.py", line 499, in scope
    return self.parent.scope()
  File "/tmp/x/venv/lib/python3.6/site-packages/astroid/node_classes.py", line 499, in scope
    return self.parent.scope()
  File "/tmp/x/venv/lib/python3.6/site-packages/astroid/node_classes.py", line 499, in scope
    return self.parent.scope()
AttributeError: 'arg' object has no attribute 'scope'

Expected behavior

Anything but crash

pylint --version output

$ pylint --version
pylint 2.4.2
astroid 2.3.1
Python 3.6.8 (default, Jan 14 2019, 11:02:34) 
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]]
@asottile
Copy link
Contributor Author

asottile commented Oct 8, 2019

The workaround for now is to request pylint<2.4 and astroid<2.3

PCManticore added a commit to pylint-dev/astroid that referenced this issue Oct 9, 2019
Until now they had as parent the builtin `ast` node which meant
we were operating with primitive objects instead of our own.

Close pylint-dev/pylint#3174
@PCManticore
Copy link
Contributor

Thanks for reporting the issue @asottile ! It's fixed in astroid, I'll release it shortly as 2.3.2.

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

No branches or pull requests

2 participants