On 01/12/2012 09:14 AM, osimons wrote:
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?
Yes.
> 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.
...
Lesson: Don't copy or deepcopy objects unless either you or the class
know exactly what needs to be done.
Thanks for the explanation. I'll find another way.
Which leads me to ask why:
# Remember original pred, succ values
pred = {}
succ = {}
for tid in ticketsByID:
pred[tid] = copy.copy(ticketsByID[tid]['pred'])
succ[tid] = copy.copy(ticketsByID[tid]['succ'])
# Update pred, succ as needed for scheduling
_augmentTickets(ticketsByID)
for id in ticketsByID:
if options['schedule'] == 'alap':
_schedule_task_alap(ticketsByID[id])
else:
_schedule_task_asap(ticketsByID[id])
# Put original pred, succ back
for tid in ticketsByID:
ticketsByID[tid]['pred'] = pred[tid]
ticketsByID[tid]['succ'] = succ[tid]
leaves the scheduler changes to pred and succ visible to the caller.
--
Christopher Nelson, Software Engineering Manager
SIXNET - Solutions for Your Industrial Networking Challenges
331 Ushers Road, Ballston Lake, NY 12019
Tel: +1.518.877.5173, Fax: +1.518.877.8346 www.sixnet.com
--
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.