Make name lookups follow MRO within a class definition

This seems like a really bad idea to be honest and will probably cause some subtle and confusing bugs. The scope should never be invisible to you, if you go to a scope that’s potentially outside your current file it should be made explicit (self, super(), import, …).

Inside a class body something as dynamic as super() doesn’t really make that much sense because the lookup happens the moment the class body is evaluated, so it is static for all intents and purposes, at best it would save you the trouble of having to remember which base class the attribute was defined on in a multiple inheritance scenario, but I also think it’s dangerous, since it fools people into thinking super() at class level does the same thing as it does at instance level.

The only real way to defer that lookup, so dependency injection works correctly, is to use a classmethod, you could maybe generalize it to a few additional scenarios using a custom descriptor, but I don’t think you could make it behave sanely in all circumstances. So I think making it more cumbersome is actually a good thing here, since you have to think about these things.

7 Likes