Whoops. I totally misread that! My brain unhelpfully supplied string quotes in the return statement of the `eggs` methods, rather than parsing them as function calls. ...for some reason I could not explain to you.
Maybe I've grown too dependent on syntax highlighting!
I see what Steven meant now. Ignore what I typed earlier, then.
To be honest, I do completely agree. I think the most useful and least surprising implementation would be to give the namespace block its own temporary scope (with outer names still available), and then only at the end of the block just before the scope is destroyed do any names bound to it get set on the parent scope.
return "spam spam spam!"
old_spam = spam # No NameError, the `spam` from module scope is still accessible here if we want it!
return "There's not much call for spam here."
new_spam = spam # this now refers to the function defined immediately above
return spam() # this refers to the same object as `new_spam`, not the `spam` from globals()
# at this point globals()['Shop.spam'] would still raise a NameError. It doesn't exist yet!
this_is_shop_spam = spam # However, we can access it from inside another nested namespace as a simple name. The scoping rules on nested classes would not allow this!
# at this point globals()['Shop.spam'] exists!
Sorry Steven! I totally misunderstood your example. It was a really good point. Thanks :)