|
35 | 35 | # o # --> o |
36 | 36 | # with autoref(p): |
37 | 37 | # # the outer autoref just needs to insert its obj to the arglist |
38 | | -# x # --> (lambda _ar314: _ar314[1] if _ar314[0] else x)(*_autoref_resolve((p, o, "x"))) |
39 | | -# x.a # --> ((lambda _ar314: _ar314[1] if _ar314[0] else x)(*_autoref_resolve((p, o, "x"))).a |
40 | | -# x[s] # --> ((lambda _ar314: _ar314[1] if _ar314[0] else x)(*_autoref_resolve((p, o, "x")))[s] |
| 38 | +# x # --> (lambda _ar314: _ar314[1] if _ar314[0] else x)(_autoref_resolve((p, o, "x"))) |
| 39 | +# x.a # --> ((lambda _ar314: _ar314[1] if _ar314[0] else x)(_autoref_resolve((p, o, "x"))).a |
| 40 | +# x[s] # --> ((lambda _ar314: _ar314[1] if _ar314[0] else x)(_autoref_resolve((p, o, "x")))[s] |
41 | 41 | # # these are transformed when the **outer** autoref transforms |
42 | | -# o # --> (lambda _ar314: _ar314[1] if _ar314[0] else o)(*_autoref_resolve((p, "o"))) |
43 | | -# o.x # --> ((lambda _ar314: _ar314[1] if _ar314[0] else o)(*_autoref_resolve((p, "o")))).x |
44 | | -# o[s] # --> ((lambda _ar314: _ar314[1] if _ar314[0] else o)(*_autoref_resolve((p, "o"))))[s] |
| 42 | +# o # --> (lambda _ar314: _ar314[1] if _ar314[0] else o)(_autoref_resolve((p, "o"))) |
| 43 | +# o.x # --> ((lambda _ar314: _ar314[1] if _ar314[0] else o)(_autoref_resolve((p, "o")))).x |
| 44 | +# o[s] # --> ((lambda _ar314: _ar314[1] if _ar314[0] else o)(_autoref_resolve((p, "o"))))[s] |
45 | 45 | # |
46 | | -# The lambda is needed, because the lexical-variable lookup for ``x`` must occur at the use site. |
47 | | -# We could modify ``_autoref_resolve`` to look in ``locals()``, too (and pass it in), but that |
48 | | -# leads to an unnecessary performance hit. |
| 46 | +# The lambda is needed, because the lexical-variable lookup for ``x`` must occur at the use site, |
| 47 | +# and it can only be performed by Python itself. We could modify ``_autoref_resolve`` to take |
| 48 | +# ``locals()`` and ``globals()`` as arguments and look also in the ``builtins`` module, |
| 49 | +# but that way we get no access to the enclosing scopes (the "E" in LEGB). |
49 | 50 | # |
50 | 51 | # Recall the blocks expand from inside out. Here ``_ar*`` are gensyms. A single unique name |
51 | 52 | # for the parameter of the lambdas would be sufficient, but this is easier to arrange. |
|
0 commit comments