astroid icon indicating copy to clipboard operation
astroid copied to clipboard

support no-member and type inference for attrs classes?

Open belm0 opened this issue 6 years ago • 3 comments

Currently it seems that the attrs plugin only aims to avoid false warnings.

I'd like it to also support detection of nonexistent members (no-member), and be able to use available member type information.

I don't observe that astroid does either of these currently, and the plugin tests are limited to "does a Factory dict attribute infer as Unknown".

belm0 avatar Nov 19 '19 06:11 belm0

Would you be able to submit a patch? While I agree that makes sense, it's not something we can prioritize now, but having a PR from a contributor would definitely improve the attrs support.

PCManticore avatar Nov 19 '19 08:11 PCManticore

correction: no-member works (it's no different than plain class attributes)

and I guess before wanting type annotations to work for attrs classes, it should work on plain classes:

class Test:
    def foo(self): pass

class AttribClass:
    x: int
    o = Test()
    o2: Test

obj = AttribClass()
assert obj.x
assert obj.y  # "Instance of 'AttribClass' has no 'y' member"
assert obj.o.foo2()  # "Instance of 'Test' has no 'foo2' member"
assert obj.o2.foo2()  # expected error

belm0 avatar Nov 19 '19 11:11 belm0

Here's a test case for this issue that demonstrates the problem: https://github.com/PyCQA/astroid/pull/750

webknjaz avatar Feb 10 '20 14:02 webknjaz