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 to self because of the way is created via object.__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 to self.
- Also recognize
object.__new__ calls via super(...).
In this example (from #982) we define an attribute via assignment in
__new__:Currently mypy doesn't recognize attribute
fooand complains aboutx.foo. To implement this, we could do these things:objis something similar toselfbecause of the way is created viaobject.__new__. This should happen during semantic analysis so that this will work in unannotated method as well.objbecause it is classified as similar toself.object.__new__calls viasuper(...).