[Python-3000] Iterators for dict keys, values, and items == annoying :)

Paul Moore p.f.moore at gmail.com
Fri Mar 31 14:18:17 CEST 2006


On 3/31/06, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Alex Martelli wrote:
>
> > If the framework consuming X requested adaptation-to-X on all objects
>  > it's passed,
>
> This is the part that bothers me, I think. It
> seems like all these adaptation requests would
> be a huge burden on the framework developer.

That *is* the big stumbling block, I agree. However, where it's used,
I've generally found adaptation to be a nice solution (although I've
only written "learning" or "toy" code, so I don't have
production-level experience to back this up).

But it's not true that you have to do this from day one. You can leave
your framework as it is, and only add adaptation when it's needed. The
__index__ example is a good one here - for a long time, __index__
didn't exist. But in the end, the requirement to index with
user-defined types became sufficiently pressing that a solution was
needed. The "traditional" solution, __index__, requires co-operation
from all classes that want to support the new protocol. Adaptation
doesn't - it can be added externally. The downside of adaptation is
that it either requires buy-in to an existing interface framework
(zope interfaces, PyProtocols, whatever) or it requires language
(stdlib) support.

Rather than being a solution looking for a problem, I suspect it's
more of a chicken and egg issue. But either way it's a stumbling
block.

Paul.


More information about the Python-3000 mailing list