Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tiago Peixoto
graph-tool
Commits
50f53515
Commit
50f53515
authored
Oct 01, 2012
by
Tiago Peixoto
Browse files
Slightly modify and clarify the one-way proxy behavior of internal property dictionaries
This fixes ticket
#110
parent
ae2b9c4f
Changes
2
Hide whitespace changes
Inline
Side-by-side
doc/graph_tool.rst
View file @
50f53515
...
...
@@ -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
...
...
src/graph_tool/__init__.py
View file @
50f53515
...
...
@@ -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
)
...
...
Tiago Peixoto
@count0
mentioned in issue
#157 (closed)
·
Aug 06, 2014
mentioned in issue
#157 (closed)
mentioned in issue #157
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment