mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-14 18:05:27 +07:00
Traversing through all children of a PyFunction looking for nested functions, possibly declaring a nonlocal or global variable, and doing that for every target expression or a reference to one, is both inefficient and seemingly hardly needed. For a name being local means that it cannot be accessed outside the scope of the corresponding function. Updating this variable from some inner helper function doesn't violate this property. In Python, one has to explicitly mark a name from an enclosing scope as nonlocal or global to be able to assign to it within a function. It seems enough (and less surprising) to rely on this information to distinguish between local variables and everything else. All in all, if some local variable is accessed as a nonlocal name in an inner function, it's now still highlighted as local in the function that defines it (previously it wasn't), but it is not in the function declaring it as nonlocal (same as before). Additionally, we now uniformly highlight as local variables "for" and "with" statement targets, targets of assignment expressions, names bound in patterns, and variables in assignments with unpacking (previously it was done only for trivial assignments). GitOrigin-RevId: 04c07ae6814a6b531911b3d87a3a26191c934962
7 lines
295 B
Python
7 lines
295 B
Python
def <info descr="PY.FUNC_DEFINITION">outer</info>():
|
|
<info descr="PY.LOCAL_VARIABLE">x</info> = "John"
|
|
def <info descr="PY.NESTED_FUNC_DEFINITION">inner</info>():
|
|
nonlocal x
|
|
x = "hello"
|
|
<info descr="PY.FUNCTION_CALL">inner</info>()
|
|
return <info descr="PY.LOCAL_VARIABLE">x</info> |