Dec
21
How lookup works
The documentation does a great job explaining how things normally get looked up, and how you can hook them.
But to understand how the hooking works, you need to go under the covers to see how that normal lookup actually happens.
When I say "Python" below, I'm mostly talking about CPython 3.5. Other implementations vary to differing degrees in how they implement things; they just have to result in the same rules being followed.
Variables: LEGB
Python has simple lexical scoping, like most other languages. (Unlike many languages, only module, function, and class definitions create new scopes, not every suite, but that's not too important here.
But to understand how the hooking works, you need to go under the covers to see how that normal lookup actually happens.
When I say "Python" below, I'm mostly talking about CPython 3.5. Other implementations vary to differing degrees in how they implement things; they just have to result in the same rules being followed.
Variables: LEGB
Python has simple lexical scoping, like most other languages. (Unlike many languages, only module, function, and class definitions create new scopes, not every suite, but that's not too important here.