Open
Description
In this example (from #982) we define an attribute via assignment in __new__
:
class C(object):
def __new__(cls, foo=None):
obj = object.__new__(cls)
obj.foo = foo
return obj
x = C(foo=12)
print(x.foo)
Currently mypy doesn't recognize attribute foo
and complains about x.foo
. To implement this, we could do these things:
- Infer the fact that
obj
is something similar toself
because of the way is created viaobject.__new__
. This should happen during semantic analysis so that this will work in unannotated method as well. - Infer attributes from assignments via
obj
because it is classified as similar toself
. - Also recognize
object.__new__
calls viasuper(...)
.