From 597ee31c54ef519a09b117b59f1a76051be13f71 Mon Sep 17 00:00:00 2001 From: Andrei Bondarenko Date: Sat, 24 Jul 2021 21:59:48 +0200 Subject: [PATCH] state now properly uses and it typed with UUID --- core/manager.py | 0 state/base.py | 10 +++++----- state/devstate.py | 13 +++++++------ 3 files changed, 12 insertions(+), 11 deletions(-) delete mode 100644 core/manager.py diff --git a/core/manager.py b/core/manager.py deleted file mode 100644 index e69de29..0000000 diff --git a/state/base.py b/state/base.py index 242c4b7..06e792f 100644 --- a/state/base.py +++ b/state/base.py @@ -1,6 +1,6 @@ from abc import ABC, abstractmethod from typing import Any, List, Tuple, Optional, Union -import uuid +from uuid import UUID, uuid4 primitive_types = (int, float, str, bool) INTEGER = ("Integer",) @@ -11,8 +11,8 @@ TYPE = ("Type",) type_values = (INTEGER, FLOAT, STRING, BOOLEAN, TYPE) -Node = str -Edge = str +Node = UUID +Edge = UUID Element = Union[Node, Edge] @@ -25,11 +25,11 @@ class State(ABC): """ @staticmethod - def new_id() -> str: + def new_id() -> UUID: """ Generates a new UUID """ - return str(uuid.uuid4()) + return uuid4() @staticmethod def is_valid_datavalue(value: Any) -> bool: diff --git a/state/devstate.py b/state/devstate.py index 798d8d9..6c7f853 100644 --- a/state/devstate.py +++ b/state/devstate.py @@ -1,4 +1,5 @@ from state.pystate import PyState +from uuid import UUID class DevState(PyState): @@ -13,9 +14,9 @@ class DevState(PyState): super().__init__() @staticmethod - def new_id() -> str: + def new_id() -> UUID: 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): """Dumps the whole MV graph to a graphviz .dot-file @@ -34,13 +35,13 @@ class DevState(PyState): else: x = repr(x) f.write("\"a_%s\" [label=\"%s\"];\n" % ( - n, x.replace('"', '\\"'))) + n.int, x.replace('"', '\\"'))) else: f.write("\"a_%s\" [label=\"\"];\n" % n) 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\" -> \"a_%s\" [arrowhead=none];\n" % (e[0], i)) - f.write("\"a_%s\" -> \"a_%s\";\n" % (i, e[1])) + 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].int, i.int)) + f.write("\"a_%s\" -> \"a_%s\";\n" % (i.int, e[1].int)) f.write("}") if png_path is not None: