[Python-ideas] Tweaking closures and lexical scoping to include the function being defined

Nick Coghlan ncoghlan at gmail.com
Sun Oct 2 17:02:14 CEST 2011


On Sun, Oct 2, 2011 at 10:30 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> While we're throwing around colours for the bike-shed, the colour which
> seems to look best to me is:
>
>
> def global_counter(x, [n=0, lock=lock]):  # inside the parameter list
>    ...
>
> rather than
>
> def global_counter(x) [n=0, lock=lock]:  # outside the parameter list
>    ...

The main problem I have with 'inside the parameter' list is the way it
looks when there's only state and no arguments:

    def f([state=State()]):
        ...

One could be forgiven for thinking that f() accepts a single optional
positional argument in that case. Separating the two, on the other
hand, would keep things clear:

    def f() [state=State()]:
        ...

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list