Skip to content
Snippets Groups Projects

Name literals

Merged Frans Skarman requested to merge name_literals into master
2 files
+ 15
4
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 13
2
@@ -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)
Loading