Resolve obscure super errors#1535
Conversation
slozier
left a comment
There was a problem hiding this comment.
Thanks for the PR! I'm sure I've come across the super alias issue before but I can't find any issue about it... Looks good to me. My understanding of this part of the code base is somewhat limited so I will defer to you - feel free to merge when you're happy with it.
In case you're interested in another obscure error:
class C:
def f2(self):
s_p_r = super
return s_p_r()
C().f2()
Thanks, it is a good one. I think I will adjust the part that triggers the class cell generation, but not the part that lifts It a way it then becomes another case like #562. So this will be fully solved if #562 gets solved. |
It started when I looked into why
super()generatesNameError/UnboundLocalErrorwhile in CPython it isRuntimeError(tested for by StdLib). It turns out that the CPython's implementation hence behaviour is different in some corner cases. Specifically, 0-argumentsuper()does not have default arguments__class__andselfinjected during compilation, but resolved during runtime. One of the consequences is that__class__is always resolved to a class cell rather than whatever the namebinder finds in the local scope.As far as I can see, these are truly obscure cases that would lead to IronPython/CPython differences and almost always bad Python programming, but it was an interesting exercise and you never know what other consequences might be there.
For what I know, most IronPython/CPython differences are resolved now, the only few remaining are in some pathological and totally useless constructs, in which the error message (but not type) might be different. See the new tests for specifics.