Skip to content

Commit 80c09be

Browse files
committed
improve docstring; add CAUTION about upcoming change in v0.15.0
1 parent 2e414db commit 80c09be

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

unpythonic/syntax/scopeanalyzer.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,41 @@
2121
Deletions of nonlocals and globals are ignored, because those are too dynamic
2222
for static analysis to make sense.
2323
24-
Scope analysis for Python is unnecessarily complicated, because it conflates
25-
definition and rebinding - in any language that keeps these separate, the `global`
26-
and `nonlocal` keywords aren't needed. For discussion on this point, see:
24+
25+
**CAUTION**:
26+
27+
What we do currently (before v0.15.0) doesn't fully make sense.
28+
29+
Scope - in the sense of controlling lexical name resolution - is a static
30+
(purely lexical) concept, but whether a particular name (once lexically
31+
resolved) has been initialized (or, say, whether it has been deleted) is a
32+
dynamic (run-time) feature. (I would say "property", if that word didn't
33+
have an entirely different technical meaning in Python.)
34+
35+
Consider deleting a name in one branch of an `if`/`else`. After that
36+
`if`/`else`, is the name still defined or not? Of course, with very few
37+
exceptional trivial cases such as `if 1`, this depends on the condition
38+
part of the `if` at run time, and thus can't be statically determined.
39+
40+
In order to make more sense, in v0.15.0, we will migrate to a fully static analysis.
41+
This will make the analyzer consistent with how Python itself handles scoping,
42+
at the cost of slightly (but backward-incompatibly) changing the semantics of
43+
some corner cases in the usage of `let` and `do`.
44+
45+
As of v0.14.3, a fully lexical mode has been added to `get_lexical_variables`
46+
(which, up to v0.14.2, used to be called `getshadowers`), and is enabled by default.
47+
48+
It is disabled when `scoped_walker` calls `get_lexical_variables`, to preserve
49+
old behavior until the next opportunity for a public interface change.
50+
In v0.15.0, we will make `scoped_walker` use the fully lexical mode.
51+
52+
53+
**NOTE**:
54+
55+
Scope analysis for Python is complicated, because the language's syntax
56+
conflates definition and rebinding. In any language that keeps these separate,
57+
the `global` and `nonlocal` keywords aren't needed. For discussion on this
58+
point, and on the need for an "uninitialized" special value (called ☠), see:
2759
2860
Joe Gibbs Politz, Alejandro Martinez, Matthew Milano, Sumner Warren,
2961
Daniel Patterson, Junsong Li, Anand Chitipothu, Shriram Krishnamurthi, 2013,

0 commit comments

Comments
 (0)