[Python-ideas] Before and after the colon in funciton defs.
Mike Graham
mikegraham at gmail.com
Fri Sep 23 13:59:30 CEST 2011
On Wed, Sep 21, 2011 at 1:19 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> On Wed, Sep 21, 2011 at 1:36 PM, Terry Reedy <tjreedy at udel.edu> wrote:
>> For those not party to the earlier threads, this alternate proposal would
>> bread any code that monkeypatches an imported-module-only override of a
>> builtin, something like:
>>
>> def mylen(o): return <whatever>
>> import mod; mod.len = mylen
>>
>> ...
>
> The two sticking points tend to be open() and print(). Overriding
> those externally can be *incredibly* useful for testing code that uses
> them, as well as in interacting with code that wasn't designed in a
> flexible way.
>
> Regardless, I'm going to stop mentioning the manual micro-optimisation
> use case for the default argument hack. Alex Gaynor pointed out that
> that aspect is completely irrelevant on PyPy, and as Guido notes,
> there are likely other ways to tackle name lookup optimisation even in
> CPython.
>
> ...
With the right tooling, even given these semantics, we could
monkeypatch by getting in at module runtime. One system that uses an
idea suitable for this is exocet, which was introduced with this blog
post - http://washort.twistedmatrix.com/2011/01/introducing-exocet.html
. I'm don't think exocet today is appropriate for use, but its basic
ideas could make for much more controlled tests, and become necessary
in the face of these optimizations.
Mike
More information about the Python-ideas
mailing list