On Jan 12, 2:25 pm, Chris Nelson <[email protected]> wrote:
> > ... But the ticket attritbutes weren't copied, only the references to them.
> >   I tried but deepcopy() but that gives:
> >    TypeError: __init__() takes exactly 3 arguments (1 given)
> > ...
>
> http://grokbase.com/p/python.org/python-list/2009/01/how-to-deepcopy-...
> notes:
>
>  A subclass of list should populate the list in __init__, not __new__,
> usually by calling list.__init__, as lists are mutable and subclasses
> thereof should be too.
>
> I don't believe TracPM has any subclass of list and I think Ticket
> maybe which suggests to me there's something wrong in Trac core.  With
> a little support, I'll work on the patch but core is unfamiliar to me.

And 'tickets' in your code snippet is what exactly - a list of trac
ticket objects? If so, they are objects with various internals that
you can not depend on copy or deepcopy to handle. The
trac.ticket.model.Ticket class uses __getitem__ and __setitem__ to
appear as dict, but the actual dict with the information is stored in
t.values.

A Ticket object may also have objects of other classes attached, like
self.resource (from trac.resource.Resource) and having it 'copied'
will either be impossible, wrong, uncertain or all those things...
However, when classes have __copy__() and __deepcopy__() methods,
those could contain the logic for the object to reliably copy itself
in a way that accounts for all its intricate internals. See
http://docs.python.org/library/copy.html (at end of page).

Lesson: Don't copy or deepcopy objects unless either you or the class
know exactly what needs to be done.


:::simon

https://www.coderesort.com
http://trac-hacks.org/wiki/osimons

-- 
You received this message because you are subscribed to the Google Groups "Trac 
Development" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/trac-dev?hl=en.

Reply via email to