3 ms·
> That’s standard practice - if you use `nonlocal` people reading the code will expect to see writes to the variables. Since when? I was under the impression P
by LoganDark 2y ago
> That’s standard practice - if you use `nonlocal` people reading the code will expect to see writes to the variables.
Since when? I was under the impression Python virtually doesn't have lexical scoping at all and that's why `nonlocal` exists. I mean hell, in CPython you can literally access and modify the local variables of your caller (and everything else up the call stack too). I never associated `nonlocal` at all with specifically writes. Just access in general.
- pansa2 2y ago> I was under the impression Python virtually doesn't have lexical scoping at all and that's why `nonlocal` exists Python has had lexical scoping since version 2.2. PEP 227 [0] "describes the addition of statically nested scoping (lexical scoping)" - allowing access to (but not assignment to) names in outer scopes. `nonlocal` was introduced later, in Python 3.0 [1], specifically to allow assignment to names in outer scopes. [0] https://peps.python.org/pep-0227/ https://peps.python.org/pep-0227/ [1] https://peps.python.org/pep-3104/ https://peps.python.org/pep-3104/