Unsupported object typing when using `attr.ib` with `default`
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
- 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() - 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
@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.
Here's for example the current attrs transform: https://github.com/PyCQA/astroid/blob/master/astroid/brain/brain_attrs.py