add AbstractView

This commit is contained in:
Jan Petykiewicz 2023-01-23 22:48:31 -08:00 committed by jan
parent 090e86644a
commit a6cb276468
2 changed files with 20 additions and 1 deletions

View File

@ -33,7 +33,7 @@ from .label import Label
from .ref import Ref from .ref import Ref
from .pattern import Pattern from .pattern import Pattern
from .utils import layer_t, annotations_t from .utils import layer_t, annotations_t
from .library import Library, MutableLibrary, WrapROLibrary, WrapLibrary, LazyLibrary from .library import Library, MutableLibrary, WrapROLibrary, WrapLibrary, LazyLibrary, AbstractView
from .ports import Port, PortList from .ports import Port, PortList
from .builder import Builder, Abstract, Tool from .builder import Builder, Abstract, Tool

View File

@ -42,6 +42,9 @@ class Library(Mapping[str, Pattern], metaclass=ABCMeta):
#__contains__, keys, items, values, get, __eq__, __ne__ supplied by Mapping #__contains__, keys, items, values, get, __eq__, __ne__ supplied by Mapping
def abstract_view(self) -> 'AbstractView':
return AbstractView(self)
def abstract(self, name: str) -> Abstract: def abstract(self, name: str) -> Abstract:
""" """
Return an `Abstract` (name & ports) for the pattern in question. Return an `Abstract` (name & ports) for the pattern in question.
@ -766,3 +769,19 @@ class LazyLibrary(MutableLibrary):
def __deepcopy__(self, memo: Optional[Dict] = None) -> 'LazyLibrary': def __deepcopy__(self, memo: Optional[Dict] = None) -> 'LazyLibrary':
raise LibraryError('LazyLibrary cannot be deepcopied (deepcopy doesn\'t descend into closures)') raise LibraryError('LazyLibrary cannot be deepcopied (deepcopy doesn\'t descend into closures)')
class AbstractView(Mapping[str, Abstract]):
library: Library
def __init__(self, library: Library) -> None:
self.library = library
def __getitem__(self, key: str) -> Abstract:
return self.library.abstract(key)
def __iter__(self) -> Iterator[str]:
return self.library.__iter__()
def __len__(self) -> int:
return self.library.__len__()