Consider this code:
class Bar(object): pass
class Foo(object):
def bar(self): return Bar()
f = Foo()
def Bar(): pass
print(f.bar())
It prints None
. But the poor guy bar
didn't expect Bar
to be what it became afterward!
My question is, what is the "best" (most elegant, most efficient, most Pythonic, whatever) code I can write inside of Foo
(hopefully without polluting outside scopes) that will make sure bar
can reference the Bar
that was defined at the time of its declaration rather than invocation?
(It's not that I can't come up with any solutions, but rather it's that I don't know what the proper solution is.)