Skip to content

Commit 7fdfb5f

Browse files
committed
fix bug in network
1 parent 0778515 commit 7fdfb5f

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

src/compas/datastructures/graph/graph.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ def index_uv(self):
366366
# builders
367367
# --------------------------------------------------------------------------
368368

369-
def add_node(self, key, attr_dict=None, **kwattr):
369+
def add_node(self, key=None, attr_dict=None, **kwattr):
370370
"""Add a node and specify its attributes (optional).
371371
372372
Parameters
@@ -381,7 +381,7 @@ def add_node(self, key, attr_dict=None, **kwattr):
381381
382382
Returns
383383
-------
384-
str
384+
hashable
385385
The key of the node.
386386
387387
Notes
@@ -396,6 +396,14 @@ def add_node(self, key, attr_dict=None, **kwattr):
396396
--------
397397
>>>
398398
"""
399+
if key is None:
400+
key = self._max_node = self._max_node + 1
401+
try:
402+
if key > self._max_node:
403+
self._max_node = key
404+
except (ValueError, TypeError):
405+
pass
406+
399407
if key not in self.node:
400408
self.node[key] = {}
401409
self.edge[key] = {}

src/compas/datastructures/network/network.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -327,16 +327,6 @@ def gkey_key(self, precision=None):
327327
# builders
328328
# --------------------------------------------------------------------------
329329

330-
def add_node(self, key=None, attr_dict=None, **kwattr):
331-
if key is None:
332-
key = self._max_int_key = self._max_int_key + 1
333-
try:
334-
if key > self._max_int_key:
335-
self._max_int_key = key
336-
except (ValueError, TypeError):
337-
pass
338-
return super(Network, self).add_node(key, attr_dict=attr_dict, **kwattr)
339-
340330
# --------------------------------------------------------------------------
341331
# modifiers
342332
# --------------------------------------------------------------------------

0 commit comments

Comments
 (0)