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

Decorator attrib unsupperoted where attr.ib is #628

Closed
gavento opened this issue Dec 11, 2018 · 2 comments · Fixed by #629
Closed

Decorator attrib unsupperoted where attr.ib is #628

gavento opened this issue Dec 11, 2018 · 2 comments · Fixed by #629
Labels

Comments

@gavento
Copy link
Contributor

gavento commented Dec 11, 2018

While pylint supports attr classes with attr.ib attributes, it does not support the same with attr.attrib, which is an alias preferred by some.

Steps to reproduce

  1. pylint attrib_test.py with:
import attr
from attr import attrib, attrs

@attr.s
class D1:
    d = attr.ib()

@attrs
class D2:
    d = attrib()

@attr.s
class OK:
    x1 = attr.ib(type=D1)
    x2 = attr.ib(type=D2)

    def test(self):
        return (self.x1.d, self.x2.d)

@attrs
class Err:
    x1 = attrib(type=D1)
    x2 = attrib(type=D2)

    def test(self):
        return (self.x1.d, self.x2.d)

Current behavior

Class OK reports no errors while Err reports:

[... snip docstring and too-few-methods lints]
tst.py:26:16: E1101: Instance of '_CountingAttr' has no 'd' member (no-member)
tst.py:26:27: E1101: Instance of '_CountingAttr' has no 'd' member (no-member)
[... snip docstring and too-few-methods lints]

Note the problem is not in how classes D1, D2 were declared (attr.ib or attrib).

Expected behavior

class Err should also return no errors.

python -c "from astroid import __pkginfo__; print(__pkginfo__.version)" output

2.1.0

@gavento
Copy link
Contributor Author

gavento commented Dec 11, 2018

It seems that recognizing attr annotations in https://github.com/PyCQA/astroid/blob/master/astroid/brain/brain_attrs.py is incomplete (both for classes and attributes).

@PCManticore
Copy link
Contributor

@gavento That's true. Would you like to submit a patch?

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

Successfully merging a pull request may close this issue.

2 participants