add AbstractView
This commit is contained in:
parent
090e86644a
commit
a6cb276468
@ -33,7 +33,7 @@ from .label import Label
|
||||
from .ref import Ref
|
||||
from .pattern import Pattern
|
||||
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 .builder import Builder, Abstract, Tool
|
||||
|
||||
|
@ -42,6 +42,9 @@ class Library(Mapping[str, Pattern], metaclass=ABCMeta):
|
||||
|
||||
#__contains__, keys, items, values, get, __eq__, __ne__ supplied by Mapping
|
||||
|
||||
def abstract_view(self) -> 'AbstractView':
|
||||
return AbstractView(self)
|
||||
|
||||
def abstract(self, name: str) -> Abstract:
|
||||
"""
|
||||
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':
|
||||
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__()
|
||||
|
Loading…
Reference in New Issue
Block a user