Scope and Name Resolution
Tython uses lexical scope with strict declaration rules.
Scope Kinds
- Module scope
- Function scope
- Block scope
Block scope exists in if, else, loops, and explicit braces.
Rules
Declaration Before Use
A name must be declared before it is used.
No Hoisting
Names become visible only from their declaration line forward.
No Implicit Global Assignment
Assignment to undeclared names is an error.
No Redeclaration in the Same Scope
No Shadowing
A nested scope cannot reuse a name from an accessible outer local scope.
Branch-Local Names Stay Local
Bindings declared inside a branch do not escape that branch.
Use an outer declaration when branch results need to be shared.
Nested Functions
Nested function declarations are not allowed in v1.