Providing type hint for an attribute of an attribute (i.e. for y in self.x.y)
This works:
self.x #type: int
But this doesn't:
self.x.y #type: int
Is it possible to provide a hint for an attribute of an attribute? Unfortunately I can't modify the code of x itself.
请先登录再写评论。
I believe you have to provide the type hint in the inner object.
In your example, the x object can have a type hint for y.
Note the check() function in the following examples
I've even gone so far as to type hint attributes (type hint x) just to avoid some traceability issues that have popped up once in a while for object attributes.