pylint-dev / pylint-dev/astroid
Unsupported object typing when using `attr.ib` with `default`
- Dominant language
- Python
- Stars
- 582
- Forks
- 357
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
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:
```python
# 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
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.