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

Unsupported object typing when using attr.ib with default #656

Open
danie1k opened this issue Mar 15, 2019 · 2 comments
Open

Unsupported object typing when using attr.ib with default #656

danie1k opened this issue Mar 15, 2019 · 2 comments
Labels

Comments

@danie1k
Copy link

danie1k commented Mar 15, 2019

This issue seems to be similar/continuation to #628.
pylint misunderstood typing when using attr.ib(default=...).

I've tried typing.cast & attr.ib with type attr and the result is the same.

Tested on

  • Python 3.6.8
  • pylint 2.3.1
  • astroid 2.2.5

Steps to reproduce

  1. Sample python file:
    # tst.py
    from typing import Set
    import attr
    
    class ApiKlass:
        def a_method(self):
            pass
    
    @attr.s
    class D1:
        d = attr.ib()
        api: ApiKlass = attr.ib(default=ApiKlass())
        values: Set = attr.ib(default=set)
    
        def test(self):
            return self.api.a_method
    
        def set_test(self, value: str):
            if value not in self.values:
                raise ValueError()
  2. Run pylint tst.py.

Current behavior

[skip]
tst.py:16:15: E1101: Instance of '_CountingAttr' has no 'a_method' member (no-member)
[skip]
tst.py:19:24: E1135: Value 'self.values' doesn't support membership test (unsupported-membership-test)
tst.py:13:15: E1101: Instance of '_CountingAttr' has no 'a_method' member (no-member)

Expected behavior

Line 13 (class D1) should not raise no-member & unsupported-membership-test warnings.

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

@PCManticore
Copy link
Contributor

PCManticore commented Mar 19, 2019

@danie1k Thanks for reporting the issue. Right now pylint does not understand any typing support for attrs. For each library that does things somewhat in a dynamic way, in which bucket attrs falls as well, we have to write custom inference transforms . You are seeing these issues because no one got to add support for attrib defaults just yet.

@PCManticore
Copy link
Contributor

Here's for example the current attrs transform: https://github.com/PyCQA/astroid/blob/master/astroid/brain/brain_attrs.py

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