Update to PEP 227 (static scoping)

Tim Peters tim.one at home.com
Thu Feb 22 02:32:48 CET 2001


[Denys Duchier]
> if "global x" was instead allowed to mean "the x in the innermost
> enclosing scope that defines one (or the global scope otherwise)",
> wouldn't that solve the problem.

You answered that next:

> It wouldn't be semantically backward compatible,

Bingo.

> but, in practice, would that break a lot of existing programs and
> require too high a cost for fixing them?  Just wondering.

It depends on who you ask, of course.

>From a cost/benefit view, the crushingly overwhelming source of scope
complaints comes from people using Python's little lambdas.  Indeed, there
were exceedingly few scope complaints before little lambdas were introduced,
and non-stop howling ever since.

I say "little" because they're restricted to a single expression, and
expressions in Python can never rebind a name (all binding constructs are
statements in Python, not expressions).  So the people who want lexical
scoping in Python the most (in practice, not the ones who just talk about it
or are idly pining for Scheme <wink>) have no possibility of rebinding a
name anyway in the context they most want it.

Doesn't mean Python will never allow intermediate-level bindings, but
there's very little call for it now, so it just raises more issues that
needn't be solved now.

the-ironic-thing-is-that-if-guido-were-ignoring-users-he-wouldn't-
    have-gotten-within-a-10-foot-snake-of-lexical-nesting-ly y'rs  - tim





More information about the Python-list mailing list