wting / python-graph

Automatically exported from code.google.com/p/python-graph
Other
5 stars 4 forks source link

Default Node Attributes are shared #92

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Problem can be identified with the following:

>>> from pygraph.classes.digraph import digraph
>>> gr = digraph()
>>> gr.add_node(1)
>>> gr.add_node(2)
>>> print gr.node_attributes(1)
[]
>>> print gr.node_attributes(2)
[]
>>> gr.node_attributes(1).append('hi')
>>> print gr.node_attributes(1)
['hi'] # good
>>> print gr.node_attributes(2)
['hi'] # whoops

The python list given as a default argument is mutable and shared among all 
instances.

Not sure if this was meant to be done on purpose or not. For someone who wants 
this behavior, they should probably pass in their own list and modify it 
externally.

Attached is a proposed patch.

Original issue reported on code.google.com by jonathan...@gmail.com on 10 Apr 2011 at 4:03

Attachments:

GoogleCodeExporter commented 9 years ago
This is a bug indeed. Thanks.

Original comment by pmatiello on 10 Apr 2011 at 5:15

GoogleCodeExporter commented 9 years ago
Patch applied. Check r734. Thanks!

Original comment by pmatiello on 11 Apr 2011 at 11:49