Pipe-operator does not support forward references

This commit is contained in:
Jan Petykiewicz 2023-02-23 16:23:06 -08:00
parent 28424be3db
commit f5d1fd2c29
5 changed files with 21 additions and 21 deletions

View File

@ -45,7 +45,7 @@ class Abstract(PortList):
# def build( # def build(
# self, # self,
# library: 'MutableLibrary', # library: 'MutableLibrary',
# tools: None | 'Tool' | MutableMapping[str | None, 'Tool'] = None, # tools: 'None | Tool | MutableMapping[str | None, Tool]' = None,
# ) -> 'Builder': # ) -> 'Builder':
# """ # """
# Begin building a new device around an instance of the current device # Begin building a new device around an instance of the current device

View File

@ -219,7 +219,7 @@ class Library(Mapping[str, 'Pattern'], metaclass=ABCMeta):
if isinstance(tops, str): if isinstance(tops, str):
tops = (tops,) tops = (tops,)
flattened: dict[str, 'Pattern' | None] = {} flattened: dict[str, 'Pattern | None'] = {}
def flatten_single(name) -> None: def flatten_single(name) -> None:
flattened[name] = None flattened[name] = None
@ -342,7 +342,7 @@ class Library(Mapping[str, 'Pattern'], metaclass=ABCMeta):
current_pattern = visit_after(current_pattern, **visit_args) current_pattern = visit_after(current_pattern, **visit_args)
``` ```
where `visit_args` are where `visit_args` are
`hierarchy`: (top_pattern_or_None, L1_pattern, L2_pattern, ..., parent_pattern) `hierarchy`: (top_pattern_or_None, L1_pattern, L2_pattern, ..., parent_pattern, target_pattern)
tuple of all parent-and-higher pattern names. Top pattern name may be tuple of all parent-and-higher pattern names. Top pattern name may be
`None` if not provided in first call to .dfs() `None` if not provided in first call to .dfs()
`transform`: numpy.ndarray containing cumulative `transform`: numpy.ndarray containing cumulative
@ -413,7 +413,7 @@ class Library(Mapping[str, 'Pattern'], metaclass=ABCMeta):
pattern = visit_after(pattern, hierarchy=hierarchy, memo=memo, transform=transform) pattern = visit_after(pattern, hierarchy=hierarchy, memo=memo, transform=transform)
if pattern is not original_pattern: if pattern is not original_pattern:
name = hierarchy[-1] name = hierarchy[-1] # TODO what is name=None?
if not isinstance(self, MutableLibrary): if not isinstance(self, MutableLibrary):
raise LibraryError('visit_* functions returned a new `Pattern` object' raise LibraryError('visit_* functions returned a new `Pattern` object'
' but the library is immutable') ' but the library is immutable')
@ -431,14 +431,14 @@ class MutableLibrary(Library, MutableMapping[str, 'Pattern'], metaclass=ABCMeta)
#def __getitem__(self, key: str) -> 'Pattern': #def __getitem__(self, key: str) -> 'Pattern':
#def __iter__(self) -> Iterator[str]: #def __iter__(self) -> Iterator[str]:
#def __len__(self) -> int: #def __len__(self) -> int:
#def __setitem__(self, key: str, value: 'Pattern' | Callable[[], 'Pattern']) -> None: #def __setitem__(self, key: str, value: 'Pattern | Callable[[], Pattern]') -> None:
#def __delitem__(self, key: str) -> None: #def __delitem__(self, key: str) -> None:
@abstractmethod @abstractmethod
def __setitem__( def __setitem__(
self, self,
key: str, key: str,
value: 'Pattern' | Callable[[], 'Pattern'], value: 'Pattern | Callable[[], Pattern]',
) -> None: ) -> None:
pass pass
@ -858,7 +858,7 @@ class WrapLibrary(MutableLibrary):
def __setitem__( def __setitem__(
self, self,
key: str, key: str,
value: 'Pattern' | Callable[[], 'Pattern'], value: 'Pattern | Callable[[], Pattern]',
) -> None: ) -> None:
if key in self.mapping: if key in self.mapping:
raise LibraryError(f'"{key}" already exists in the library. Overwriting is not allowed!') raise LibraryError(f'"{key}" already exists in the library. Overwriting is not allowed!')
@ -898,7 +898,7 @@ class LazyLibrary(MutableLibrary):
def __setitem__( def __setitem__(
self, self,
key: str, key: str,
value: 'Pattern' | Callable[[], 'Pattern'], value: 'Pattern | Callable[[], Pattern]',
) -> None: ) -> None:
if key in self.mapping: if key in self.mapping:
raise LibraryError(f'"{key}" already exists in the library. Overwriting is not allowed!') raise LibraryError(f'"{key}" already exists in the library. Overwriting is not allowed!')
@ -1045,7 +1045,7 @@ class Tree(MutableLibrary):
def __init__( def __init__(
self, self,
top: str | 'NamedPattern', top: 'str | NamedPattern',
library: MutableLibrary | None = None library: MutableLibrary | None = None
) -> None: ) -> None:
self.top = top if isinstance(top, str) else top.name self.top = top if isinstance(top, str) else top.name
@ -1068,7 +1068,7 @@ class Tree(MutableLibrary):
def __len__(self) -> int: def __len__(self) -> int:
return len(self.library) return len(self.library)
def __setitem__(self, key: str, value: 'Pattern' | Callable[[], 'Pattern']) -> None: def __setitem__(self, key: str, value: 'Pattern | Callable[[], Pattern]') -> None:
self.library[key] = value self.library[key] = value
def __delitem__(self, key: str) -> None: def __delitem__(self, key: str) -> None:

View File

@ -601,7 +601,7 @@ class Pattern(PortList, AnnotatableImpl, Mirrorable):
Returns: Returns:
self self
""" """
flattened: dict[str | None, 'Pattern' | None] = {} flattened: dict[str | None, 'Pattern | None'] = {}
# TODO both Library and Pattern have flatten()... pattern is in-place? # TODO both Library and Pattern have flatten()... pattern is in-place?
def flatten_single(name: str | None) -> None: def flatten_single(name: str | None) -> None:

View File

@ -46,7 +46,7 @@ class Ref(
def __init__( def __init__(
self, self,
target: str | 'NamedPattern' | None, target: 'str | NamedPattern | None',
*, *,
offset: ArrayLike = (0.0, 0.0), offset: ArrayLike = (0.0, 0.0),
rotation: float = 0.0, rotation: float = 0.0,
@ -120,7 +120,7 @@ class Ref(
def as_pattern( def as_pattern(
self, self,
*, *,
pattern: 'Pattern' | None = None, pattern: 'Pattern | None' = None,
library: Mapping[str, 'Pattern'] | None = None, library: Mapping[str, 'Pattern'] | None = None,
) -> 'Pattern': ) -> 'Pattern':
""" """
@ -177,7 +177,7 @@ class Ref(
def get_bounds( def get_bounds(
self, self,
*, *,
pattern: 'Pattern' | None = None, pattern: 'Pattern | None' = None,
library: Mapping[str, 'Pattern'] | None = None, library: Mapping[str, 'Pattern'] | None = None,
) -> NDArray[numpy.float64] | None: ) -> NDArray[numpy.float64] | None:
""" """

View File

@ -22,7 +22,7 @@ class Repeatable(metaclass=ABCMeta):
''' '''
@property @property
@abstractmethod @abstractmethod
def repetition(self) -> 'Repetition' | None: def repetition(self) -> 'Repetition | None':
""" """
Repetition object, or None (single instance only) Repetition object, or None (single instance only)
""" """
@ -30,14 +30,14 @@ class Repeatable(metaclass=ABCMeta):
# @repetition.setter # @repetition.setter
# @abstractmethod # @abstractmethod
# def repetition(self, repetition: 'Repetition' | None): # def repetition(self, repetition: 'Repetition | None'):
# pass # pass
''' '''
---- Methods ---- Methods
''' '''
@abstractmethod @abstractmethod
def set_repetition(self, repetition: 'Repetition' | None) -> Self: def set_repetition(self, repetition: 'Repetition | None') -> Self:
""" """
Set the repetition Set the repetition
@ -56,18 +56,18 @@ class RepeatableImpl(Repeatable, metaclass=ABCMeta):
""" """
__slots__ = _empty_slots __slots__ = _empty_slots
_repetition: 'Repetition' | None _repetition: 'Repetition | None'
""" Repetition object, or None (single instance only) """ """ Repetition object, or None (single instance only) """
''' '''
---- Non-abstract properties ---- Non-abstract properties
''' '''
@property @property
def repetition(self) -> 'Repetition' | None: def repetition(self) -> 'Repetition | None':
return self._repetition return self._repetition
@repetition.setter @repetition.setter
def repetition(self, repetition: 'Repetition' | None): def repetition(self, repetition: 'Repetition | None'):
from ..repetition import Repetition from ..repetition import Repetition
if repetition is not None and not isinstance(repetition, Repetition): if repetition is not None and not isinstance(repetition, Repetition):
raise MasqueError(f'{repetition} is not a valid Repetition object!') raise MasqueError(f'{repetition} is not a valid Repetition object!')
@ -76,6 +76,6 @@ class RepeatableImpl(Repeatable, metaclass=ABCMeta):
''' '''
---- Non-abstract methods ---- Non-abstract methods
''' '''
def set_repetition(self, repetition: 'Repetition' | None) -> Self: def set_repetition(self, repetition: 'Repetition | None') -> Self:
self.repetition = repetition self.repetition = repetition
return self return self