[Python-ideas] Being able to specify

Nick Coghlan ncoghlan at gmail.com
Tue Dec 15 22:28:25 CET 2009


Terry Reedy wrote:
>> I guess so, yes. My method would be something like what Jacob said,
>> abusing
>> the memo dict to pass the copying mode. But I thought perhaps we can
>> set a
>> standard way for specifying different copy modes, because otherwise
>> I'll do my
>> memo hack and someone else will do his different memo hack and it
>> won't be
>> compatible.
> 
> Perhaps you can post a recipe at the Python Cookbook. People who care
> about compatibility can follow the same recipe.

Alternatively, this use case strikes me as being rather similar to the
various flatten() recipes out there that accept a list of "atomic" types
to avoid flattening iterable-but-not-really-a-container types such as
strings.

The analogy currently breaks due to copy.deepcopy() being set up with
each __deepcopy__ method doing its own recursion rather than
constructing a graph of mutable (to be copied) and immutable members (to
be referenced) down the chain of the object graph.

More flexible (but significantly harder) than adding a copy mode would
be defining a protocol for exposing the object graph in a standardised
fashion.

__iter__ in conjunction with __dict__ would get you a fair way, but
there would be a lot of complications.

Cheers,
Nick.

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



More information about the Python-ideas mailing list