[Python-ideas] Before and after the colon in funciton defs.
ncoghlan at gmail.com
Fri Sep 23 06:52:30 CEST 2011
On Fri, Sep 23, 2011 at 2:34 PM, Carl Matthew Johnson
<cmjohnson.mailinglist at gmail.com> wrote:
> Instead of a $ decorator, you could let decorators have a __prepare__ method that returns a dict to use for locals, as metaclasses do today.
No, locals simply don't work like that. They're handled by frame
objects and the eval loop, not function objects.
There are a whole host of complicated interactions between the
compiler's symbol table analysis and code generation, function, code
and frame objects and the runtime evaluation loop going on when it
comes to handling name lookups in Python. When you're looking at it
purely from a Python user's point of view, there are plenty of ideas
that seem potentially reasonable on the surface but simply don't fit
with the underlying data model of the language.
It's hard enough coming up with good proposals for semantic and
syntactic tweaks when you *do* know how they all work together to
achieve the current behaviour - the current setup is actually pretty
good, and the number of ways we could make it worse vastly outnumbers
the ways we could conceivably improve it.
Try to keep this discussion in perspective: we're talking about
handling a niche use case in a slightly more elegant fashion. The
magnitude of language change that can be justified for this purpose is
tiny. I've thrown plenty of ideas of my own at the task over the years
(and seen even more ideas from others), and tweaking the syntax and
semantics of nonlocal is the first of them that I've genuinely liked
better than the status quo.
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas