If I have some code like this:
x.y.z = 12
I can infer that the z
member is being indexed from the call to __setattr__
. However if I have something like this:
foo = x.y.z # situation 1
bar = x.y.z.bar # situation 2
How can I determine which of the above situations I am in, if I care to do something special for z
based on whether or not it is last in the chain of indexing? Is this kind of inference even possible in Python?
For more clarity let's assume I can change the implementation of all the objects being indexed, so using descriptors is wholly possible.
I worry that the answer to this question is "you can't do that" since it is impossible to override =
like you can in C++.