Pipe-operator does not support forward references

This commit is contained in:
Jan Petykiewicz 2023-02-23 16:23:06 -08:00 committed by jan
parent 45081c2d31
commit b4f36417fd
5 changed files with 21 additions and 21 deletions

View File

@ -45,7 +45,7 @@ class Abstract(PortList):
# def build(
# self,
# library: 'MutableLibrary',
# tools: None | 'Tool' | MutableMapping[str | None, 'Tool'] = None,
# tools: 'None | Tool | MutableMapping[str | None, Tool]' = None,
# ) -> 'Builder':
# """
# 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):
tops = (tops,)
flattened: dict[str, 'Pattern' | None] = {}
flattened: dict[str, 'Pattern | None'] = {}
def flatten_single(name) -> None:
flattened[name] = None
@ -342,7 +342,7 @@ class Library(Mapping[str, 'Pattern'], metaclass=ABCMeta):
current_pattern = visit_after(current_pattern, **visit_args)
```
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
`None` if not provided in first call to .dfs()
`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)
if pattern is not original_pattern:
name = hierarchy[-1]
name = hierarchy[-1] # TODO what is name=None?
if not isinstance(self, MutableLibrary):
raise LibraryError('visit_* functions returned a new `Pattern` object'
' but the library is immutable')
@ -431,14 +431,14 @@ class MutableLibrary(Library, MutableMapping[str, 'Pattern'], metaclass=ABCMeta)
#def __getitem__(self, key: str) -> 'Pattern':
#def __iter__(self) -> Iterator[str]:
#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:
@abstractmethod
def __setitem__(
self,
key: str,
value: 'Pattern' | Callable[[], 'Pattern'],
value: 'Pattern | Callable[[], Pattern]',
) -> None:
pass
@ -858,7 +858,7 @@ class WrapLibrary(MutableLibrary):
def __setitem__(
self,
key: str,
value: 'Pattern' | Callable[[], 'Pattern'],
value: 'Pattern | Callable[[], Pattern]',
) -> None:
if key in self.mapping:
raise LibraryError(f'"{key}" already exists in the library. Overwriting is not allowed!')
@ -898,7 +898,7 @@ class LazyLibrary(MutableLibrary):
def __setitem__(
self,
key: str,
value: 'Pattern' | Callable[[], 'Pattern'],
value: 'Pattern | Callable[[], Pattern]',
) -> None:
if key in self.mapping:
raise LibraryError(f'"{key}" already exists in the library. Overwriting is not allowed!')
@ -1045,7 +1045,7 @@ class Tree(MutableLibrary):
def __init__(
self,
top: str | 'NamedPattern',
top: 'str | NamedPattern',
library: MutableLibrary | None = None
) -> None:
self.top = top if isinstance(top, str) else top.name
@ -1068,7 +1068,7 @@ class Tree(MutableLibrary):
def __len__(self) -> int:
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
def __delitem__(self, key: str) -> None:

View File

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

View File

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

View File

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