state now properly uses and it typed with UUID
This commit is contained in:
parent
1931020bb1
commit
597ee31c54
3 changed files with 12 additions and 11 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from typing import Any, List, Tuple, Optional, Union
|
from typing import Any, List, Tuple, Optional, Union
|
||||||
import uuid
|
from uuid import UUID, uuid4
|
||||||
|
|
||||||
primitive_types = (int, float, str, bool)
|
primitive_types = (int, float, str, bool)
|
||||||
INTEGER = ("Integer",)
|
INTEGER = ("Integer",)
|
||||||
|
|
@ -11,8 +11,8 @@ TYPE = ("Type",)
|
||||||
type_values = (INTEGER, FLOAT, STRING, BOOLEAN, TYPE)
|
type_values = (INTEGER, FLOAT, STRING, BOOLEAN, TYPE)
|
||||||
|
|
||||||
|
|
||||||
Node = str
|
Node = UUID
|
||||||
Edge = str
|
Edge = UUID
|
||||||
Element = Union[Node, Edge]
|
Element = Union[Node, Edge]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -25,11 +25,11 @@ class State(ABC):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def new_id() -> str:
|
def new_id() -> UUID:
|
||||||
"""
|
"""
|
||||||
Generates a new UUID
|
Generates a new UUID
|
||||||
"""
|
"""
|
||||||
return str(uuid.uuid4())
|
return uuid4()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_valid_datavalue(value: Any) -> bool:
|
def is_valid_datavalue(value: Any) -> bool:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
from state.pystate import PyState
|
from state.pystate import PyState
|
||||||
|
from uuid import UUID
|
||||||
|
|
||||||
|
|
||||||
class DevState(PyState):
|
class DevState(PyState):
|
||||||
|
|
@ -13,9 +14,9 @@ class DevState(PyState):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def new_id() -> str:
|
def new_id() -> UUID:
|
||||||
DevState.free_id += 1
|
DevState.free_id += 1
|
||||||
return str(DevState.free_id - 1)
|
return UUID(int=DevState.free_id - 1)
|
||||||
|
|
||||||
def dump(self, path: str, png_path: str = None):
|
def dump(self, path: str, png_path: str = None):
|
||||||
"""Dumps the whole MV graph to a graphviz .dot-file
|
"""Dumps the whole MV graph to a graphviz .dot-file
|
||||||
|
|
@ -34,13 +35,13 @@ class DevState(PyState):
|
||||||
else:
|
else:
|
||||||
x = repr(x)
|
x = repr(x)
|
||||||
f.write("\"a_%s\" [label=\"%s\"];\n" % (
|
f.write("\"a_%s\" [label=\"%s\"];\n" % (
|
||||||
n, x.replace('"', '\\"')))
|
n.int, x.replace('"', '\\"')))
|
||||||
else:
|
else:
|
||||||
f.write("\"a_%s\" [label=\"\"];\n" % n)
|
f.write("\"a_%s\" [label=\"\"];\n" % n)
|
||||||
for i, e in sorted(list(self.edges.items())):
|
for i, e in sorted(list(self.edges.items())):
|
||||||
f.write("\"a_%s\" [label=\"e_%s\" shape=point];\n" % (i, i))
|
f.write("\"a_%s\" [label=\"e_%s\" shape=point];\n" % (i.int, i.int))
|
||||||
f.write("\"a_%s\" -> \"a_%s\" [arrowhead=none];\n" % (e[0], i))
|
f.write("\"a_%s\" -> \"a_%s\" [arrowhead=none];\n" % (e[0].int, i.int))
|
||||||
f.write("\"a_%s\" -> \"a_%s\";\n" % (i, e[1]))
|
f.write("\"a_%s\" -> \"a_%s\";\n" % (i.int, e[1].int))
|
||||||
f.write("}")
|
f.write("}")
|
||||||
|
|
||||||
if png_path is not None:
|
if png_path is not None:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue