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

Nick Coghlan ncoghlan at gmail.com
Thu Sep 29 20:03:31 CEST 2011


On Thu, Sep 29, 2011 at 1:41 PM, Devin Jeanpierre
<jeanpierreda at gmail.com> wrote:
>> And, as I have said several times, I agree closures currently impose
>> testability problems, but I think the answer there lies in providing
>> better introspection tools to lessen those problems rather than
>> advising people not to use closures specifically for those reasons.
>
> OK, that's fair.
>
> In order to support testing you'd need to be able to assign to closure
> variables (for e.g. mocking) and read them (to test alterations to
> global state). At that point it's a short leap to defining a decorator
> that creates these nonlocals. Is there a compelling reason to use a
> new syntax?

I don't think supporting monkey-patching is necessary - the code under
test will presumably provide some mechanism to control how the hidden
state is initialised or modified. The missing part from a testing
point of view is the ability to get that information back out in a
clean, portable way so you can make assertions about it for whitebox
testing.

Cheers,
Nick.

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



More information about the Python-ideas mailing list