[Python-ideas] Before and after the colon in funciton defs.

Eric Snow ericsnowcurrently at gmail.com
Fri Sep 23 07:31:33 CEST 2011


On Thu, Sep 22, 2011 at 10:52 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> 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.

Yeah, that's what I found out when I tried to add in an implicit
"__function__" in the locals.  I mostly had it working, but it was a
hack and a half (a lot worse than super's "@__class__" injection).

>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.

+1

-eric

>
> Regards,
> Nick.
>
> --
> Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>



More information about the Python-ideas mailing list