diff --git a/b_asic/graph_component.py b/b_asic/graph_component.py index 86018c8d85ca52afca764e6e9b604ce7fb3ae4f5..b889a3fc75d61f5571b307b130ccaeb971924386 100644 --- a/b_asic/graph_component.py +++ b/b_asic/graph_component.py @@ -7,9 +7,20 @@ Contains the base for all components with an ID in a signal flow graph. from abc import ABC, abstractmethod from collections import deque from copy import copy, deepcopy -from typing import Any, Dict, Generator, Iterable, Mapping, NewType, cast +from typing import Any, Dict, Generator, Iterable, Mapping, NewType, TypeAlias, cast +import sys + + +# We want to be able to initialize Name with String literals, but still have the +# benefit of static type checking that we don't pass non-names to name locations. +# However, until python 3.11 a string literal type was not available. In those versions, +# we'll fall back on just aliasing `str` => Name. +if sys.version_info >= (3, 11): + from typing import LiteralString + Name: TypeAlias = NewType("Name", str) | LiteralString +else: + Name = str -Name = NewType("Name", str) TypeName = NewType("TypeName", str) GraphID = NewType("GraphID", str) GraphIDNumber = NewType("GraphIDNumber", int) diff --git a/b_asic/special_operations.py b/b_asic/special_operations.py index c0609dd595296483a894271114c279dd21cfde8e..ee053221e6a5386f6585fc74df0dd9b6190695b5 100644 --- a/b_asic/special_operations.py +++ b/b_asic/special_operations.py @@ -28,12 +28,12 @@ class Input(AbstractOperation): _execution_time = 0 - def __init__(self, name: Name = Name("")): + def __init__(self, name: Name = ""): """Construct an Input operation.""" super().__init__( input_count=0, output_count=1, - name=Name(name), + name=name, latency_offsets={"out0": 0}, ) self.set_param("value", 0)