Commit 50f53515 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Slightly modify and clarify the one-way proxy behavior of internal property dictionaries

This fixes ticket #110
parent ae2b9c4f
......@@ -104,7 +104,14 @@
together with the graph itself. See :ref:`internal property maps <sec_internal_props>`
for more details.
All dictionaries below are mutable.
.. note::
All dictionaries below are mutable. However, any dictionary
returned below is only an one-way proxy to the internally-kept
properties. If you modify this object, the change will be
propagated to the internal dictionary, but not
vice-versa. Keep this in mind if you intend to keep a copy of
the returned object.
.. autoattribute:: properties
.. autoattribute:: vertex_properties
......
......@@ -840,7 +840,15 @@ def edge_difference(g, prop, ediff=None):
class PropertyDict(dict):
"""Wrapper for the dict of vertex, graph or edge properties, which sets the
value on the property map when changed in the dict."""
value on the property map when changed in the dict.
.. note::
The class is only an one-way proxy to the internally-kept properties. If
you modify this object, the change will be propagated to the internal
dictionary, but not vice-versa. Keep this in mind if you intend to keep
a copy of the class instance.
"""
def __init__(self, g, old, get_func, set_func, del_func):
dict.__init__(self)
dict.update(self, old)
......@@ -849,6 +857,13 @@ class PropertyDict(dict):
self.set_func = set_func
self.del_func = del_func
def __getitem__(self, key):
if self.get_func != None:
val = self.get_func(self.g, key)
dict.__setitem__(self, key, val)
else:
raise KeyError("Property dict cannot be gotten")
def __setitem__(self, key, val):
if self.set_func != None:
self.set_func(self.g, key, val)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment