Skip to content

Commit

Permalink
feat: allow node.id to be specified and not automatically generated (
Browse files Browse the repository at this point in the history
…mingrammer#422)

* allow node.id to be specified and not generated

* typing suport for context functions

Co-authored-by: Ivan Melnychuk <[email protected]>
  • Loading branch information
2 people authored and ngruelaneo committed Nov 25, 2022
1 parent 860ce8a commit 106411a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions diagrams/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@
__cluster = contextvars.ContextVar("cluster")


def getdiagram():
def getdiagram() -> "Diagram":
try:
return __diagram.get()
except LookupError:
return None


def setdiagram(diagram):
def setdiagram(diagram: "Diagram"):
__diagram.set(diagram)


def getcluster():
def getcluster() -> "Cluster":
try:
return __cluster.get()
except LookupError:
return None


def setcluster(cluster):
def setcluster(cluster: "Cluster"):
__cluster.set(cluster)


Expand Down Expand Up @@ -283,13 +283,13 @@ class Node:

_height = 1.9

def __init__(self, label: str = "", **attrs: Dict):
def __init__(self, label: str = "", *, nodeid: str = None, **attrs: Dict):
"""Node represents a system component.
:param label: Node label.
"""
# Generates an ID for identifying a node.
self._id = self._rand_id()
# Generates an ID for identifying a node, unless specified
self._id = nodeid or self._rand_id()
self.label = label

# fmt: off
Expand Down

0 comments on commit 106411a

Please sign in to comment.