Skip to content
Snippets Groups Projects
Commit 82384ca6 authored by Frans Skarman's avatar Frans Skarman :tropical_fish: Committed by Oscar Gustafsson
Browse files

Allow string literals to be passed to Name

parent 7c45e4c3
No related branches found
No related tags found
1 merge request!176Name literals
This commit is part of merge request !176. Comments created here will be created in the context of that merge request.
...@@ -7,9 +7,20 @@ Contains the base for all components with an ID in a signal flow graph. ...@@ -7,9 +7,20 @@ Contains the base for all components with an ID in a signal flow graph.
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from collections import deque from collections import deque
from copy import copy, deepcopy 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) TypeName = NewType("TypeName", str)
GraphID = NewType("GraphID", str) GraphID = NewType("GraphID", str)
GraphIDNumber = NewType("GraphIDNumber", int) GraphIDNumber = NewType("GraphIDNumber", int)
......
...@@ -28,12 +28,12 @@ class Input(AbstractOperation): ...@@ -28,12 +28,12 @@ class Input(AbstractOperation):
_execution_time = 0 _execution_time = 0
def __init__(self, name: Name = Name("")): def __init__(self, name: Name = ""):
"""Construct an Input operation.""" """Construct an Input operation."""
super().__init__( super().__init__(
input_count=0, input_count=0,
output_count=1, output_count=1,
name=Name(name), name=name,
latency_offsets={"out0": 0}, latency_offsets={"out0": 0},
) )
self.set_param("value", 0) self.set_param("value", 0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment