Skip to content

Commit 3282922

Browse files
committed
wip
1 parent e7457ef commit 3282922

File tree

9 files changed

+27
-13
lines changed

9 files changed

+27
-13
lines changed

edg/abstract_parts/PartsTable.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import csv
44
import itertools
5-
from typing import Generic, Type, overload, Union, Callable, List, Dict, Any, KeysView, Optional, OrderedDict, \
5+
from typing import Generic, Type, overload, Union, Callable, List, Dict, Any, KeysView, Optional, \
66
cast, Tuple, Sequence, Protocol
77

88
from typing_extensions import ParamSpec, TypeVar
@@ -83,7 +83,7 @@ def from_csv_files(cls, csv_names: List[str], encoding: str='utf-8') -> 'PartsTa
8383
return cls.from_dict_rows(dict_rows)
8484

8585
@staticmethod
86-
def from_dict_rows(*dict_rowss: Union[List[Dict[str, str]], List[OrderedDict[str, str]]]) -> 'PartsTable':
86+
def from_dict_rows(*dict_rowss: Union[List[Dict[str, str]], List[Dict[str, str]]]) -> 'PartsTable':
8787
"""Creates a parts table from dict rows, such as parsed by csv.DictReader.
8888
Checks to make sure all incoming rows are dense (have all cells)."""
8989
all_dict_rows = list(itertools.chain(*dict_rowss))

edg/abstract_parts/StandardFootprint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ class HasStandardFootprint(Block):
4848
def standard_footprint(cls) -> Type[StandardFootprint[Self]]:
4949
"""Returns the StandardFootprint class for this block"""
5050
if callable(cls._STANDARD_FOOTPRINT):
51-
return cls._STANDARD_FOOTPRINT()
51+
return cls._STANDARD_FOOTPRINT() # type: ignore
5252
else:
5353
return cls._STANDARD_FOOTPRINT

edg/core/Array.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import itertools
44
from abc import abstractmethod
55
from typing import Generic, Any, Tuple, Type, Optional, Union, Iterable, overload, Hashable, List, \
6-
ItemsView, Callable
6+
ItemsView, Callable, Dict
77

88
from deprecated import deprecated
99
from typing_extensions import TypeVar
@@ -108,7 +108,7 @@ def __init__(self, tpe: VectorType) -> None:
108108
assert not tpe._is_bound()
109109
self._tpe = tpe
110110
self._elt_sample = tpe._bind(self)
111-
self._elts: Optional[OrderedDict[str, VectorType]] = None # concrete elements, for boundary ports
111+
self._elts: Optional[Dict[str, VectorType]] = None # concrete elements, for boundary ports
112112
self._elt_next_index = 0
113113
self._requests: List[Tuple[Optional[str], BasePort]] = [] # used to track request / request_vector for ref_map
114114

edg/core/Builder.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
if TYPE_CHECKING:
1010
from .Blocks import BaseBlock
11+
from .Link import Link
12+
from .HierarchyBlock import Block
1113

1214

1315
class Builder:
@@ -41,14 +43,23 @@ def get_enclosing_block(self) -> Optional[BaseBlock]:
4143
def get_curr_context(self) -> Optional[BaseBlock]:
4244
return self.get_enclosing_block()
4345

46+
@overload
47+
def elaborate_toplevel(self, block: Block, *,
48+
is_generator: bool = False,
49+
generate_values: Iterable[Tuple[edgir.LocalPath, edgir.ValueLit]] = []) -> edgir.HierarchyBlock: ...
50+
@overload
51+
def elaborate_toplevel(self, block: Link, *,
52+
is_generator: bool = False,
53+
generate_values: Iterable[Tuple[edgir.LocalPath, edgir.ValueLit]] = []) -> edgir.Link: ...
54+
4455
def elaborate_toplevel(self, block: BaseBlock, *,
4556
is_generator: bool = False,
46-
generate_values: Iterable[Tuple[edgir.LocalPath, edgir.ValueLit]] = []) -> edgir.HierarchyBlock:
57+
generate_values: Iterable[Tuple[edgir.LocalPath, edgir.ValueLit]] = []) -> edgir.BlockLikeTypes:
4758
try:
4859
if is_generator: # TODO this is kind of nasty =(
4960
from .Generator import GeneratorBlock
5061
assert isinstance(block, GeneratorBlock)
51-
elaborated = block._generated_def_to_proto(generate_values)
62+
elaborated: edgir.BlockLikeTypes = block._generated_def_to_proto(generate_values)
5263
else: # TODO check is a GeneratorBlock w/o circular imports?
5364
elaborated = block._elaborated_def_to_proto()
5465

edg/core/Core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __init__(self, anon_prefix: Optional[str]=None) -> None:
1616
self.anon_prefix = anon_prefix
1717
self.container: Dict[str, ElementType] = {}
1818
self.names = IdentityDict[ElementType, str]() # TODO unify w/ container?
19-
self.keys_list: List = []
19+
self.keys_list: List[str] = []
2020
self.closed = False
2121

2222
def register(self, item: ElementType) -> ElementType:
@@ -80,7 +80,7 @@ def name_of(self, elt: ElementType) -> Optional[str]:
8080

8181
class SubElementManager:
8282
def __init__(self) -> None:
83-
self.dicts: List[Tuple[Union[Type, Tuple[Type, ...]], SubElementDict]] = []
83+
self.dicts: List[Tuple[Union[Type[Any], Tuple[Type[Any], ...]], SubElementDict[Any]]] = []
8484
self.aliases = IdentityDict[Any, Any]()
8585

8686
def new_dict(self, filter_type: Union[Type[ElementType], Tuple[Type[ElementType], ...]],
@@ -274,7 +274,7 @@ def _get_bases_of(cls, base_type: Type[BaseType]) -> Tuple[List[Type[BaseType]],
274274
superclasses order is not defined (but MRO in current practice).
275275
276276
mypy currently does not allow passing in abstract types, so generally calls to this need type: ignore."""
277-
direct_bases: Set[Type] = set()
277+
direct_bases: Set[Type[HasMetadata]] = set()
278278
def process_direct_base(bcls: Type[HasMetadata.BaseType]) -> None:
279279
if not issubclass(bcls, base_type):
280280
return # ignore above base_type

edg/core/Generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def get(self, param: ConstraintExpr[WrappedType, Any]) -> WrappedType:
5252
# Generator dependency data
5353
#
5454
class GeneratorRecord(NamedTuple):
55-
fn: Callable
55+
fn: Callable[..., None]
5656
req_params: Tuple[ConstraintExpr, ...] # all required params for generator to fire
5757
fn_args: Tuple[ConstraintExpr, ...] # params to unpack for the generator function
5858

edg/core/HdlUserExceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(self, exc: str, resolution: str = ""):
1212

1313
class EdgTypeError(EdslUserError):
1414
"""Argument of the wrong type passed into a EDG core function."""
15-
def __init__(self, item_desc: str, object: Any, expected_type: Union[Type, Tuple[Type, ...]]):
15+
def __init__(self, item_desc: str, object: Any, expected_type: Union[Type[Any], Tuple[Type[Any], ...]]):
1616
if isinstance(expected_type, tuple):
1717
expected_type_str = '/'.join([t.__name__ for t in expected_type])
1818
else:

edg/core/HierarchyBlock.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ def __init__(self) -> None:
288288
super().__init__()
289289

290290
if hasattr(self, '_init_params'): # used to propagate params generated in the metaclass __init__ hook
291-
for param_name, param in cast(Dict, self._init_params).items():
291+
self._init_params: Dict[str, ConstraintExpr]
292+
for param_name, param in self._init_params.items():
292293
self._parameters.register(param)
293294
self.manager.add_element(param_name, param)
294295
delattr(self, '_init_params')
@@ -320,6 +321,7 @@ def _build_ref_map(self, ref_map: Refable.RefMapType, prefix: edgir.LocalPath, *
320321

321322
def _populate_def_proto_block_base(self, pb: edgir.BlockLikeTypes) -> None:
322323
super()._populate_def_proto_block_base(pb)
324+
assert isinstance(pb, edgir.HierarchyBlock)
323325

324326
# generate param defaults
325327
for param_name, param in self._parameters.items():

edg/core/Ports.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
if TYPE_CHECKING:
1818
from .Blocks import BaseBlock
19+
from .Link import Link
1920
from .PortBlocks import PortBridge, PortAdapter
2021

2122

0 commit comments

Comments
 (0)