[Python-ideas] x=(yield from) confusion [was:Yet another alternative name for yield-from]

Nick Coghlan ncoghlan at gmail.com
Sun Apr 12 03:13:09 CEST 2009


Greg Ewing wrote:
> I definitely don't want to preclude the implementation
> from using PyIter_Next, as that would be a major
> performance hit in the most common case.

We already have a general caveat in the docs saying that an
implementation is allowed (or sometimes even required) to bypass normal
attribute lookup for special methods defined by the language. You may
want to point to that caveat from the PEP:

http://docs.python.org/reference/datamodel.html#special-method-lookup-for-new-style-classes
http://docs.python.org/3.0/reference/datamodel.html#special-method-lookup

Being able to use PyIter_Next and the various other typeslots is exactly
what that caveat is about.

One way you can make the expansion more explicit about bypassing the
instance is to write things like "type(itr).send(itr, val)" instead of
"itr.send(val)".

> I also don't want to preclude caching a send() method,
> because in the absence of a __send__ typeslot it's the
> only way we have of improving performance.

Actually, we do have another way of improving performance - add a
typeslot for it :)

That can be left until we find out whether or not the lookup of send()
becomes a performance bottleneck for yield-from usage (which I doubt
will be the case).

Cheers,
Nick.

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



More information about the Python-ideas mailing list