@@ -285,7 +285,7 @@ def __str__(self):
285285
286286class Port (pydantic .BaseModel ):
287287 type : str
288- pins : List [str ] | None # None implies must be allocated at end
288+ pins : List [Pin ] | None # None implies must be allocated at end
289289 port_name : str
290290 direction : Optional [io .Direction ] = None
291291 options : Optional [dict ] = None
@@ -430,57 +430,28 @@ def _allocate_pins(name: str, member: Dict[str, Any], pins: List[str], port_name
430430Interface = Dict [str , Port ]
431431Component = Dict [str , Interface ]
432432
433- class PortMap (MutableMapping [str , Component ]):
434- def __init__ (self , data = {}):
435- self .map : Dict [str , Component ] = data
436- return super ().__init__ ()
437- "Represents a mapping of `Port`s to Package pins, grouped by `Component` and `Interface`"
438- def __getitem__ (self , key : str ):
439- "Gets an `Component` from the map by name"
440- return self .map [key ]
441-
442- def __setitem__ (self , key : str , value : Component ):
443- "Adds or modifies a `Component` in the map by name"
444- self .map [key ] = value
445-
446- def __delitem__ (self , key : str ):
447- "Deletes a `Component` in the map by name"
448- del self .map [key ]
449-
450- def __iter__ (self ):
451- "Iterates `Component`s in the map by name"
452- return iter (self .map )
453-
454- def __len__ (self ):
455- return len (self .map )
433+ class PortMap (pydantic .BaseModel ):
434+ ports : Dict [str , Component ] = {}
456435
457436 def _add_port (self , component : str , interface : str , port_name : str , port : Port ):
458437 "Internally used by a `PackageDef`"
459- if component not in self :
460- self [component ] = {}
461- if interface not in self [component ]:
462- self [component ][interface ] = {}
463- self [component ][interface ][port_name ] = port
438+ if component not in self . ports :
439+ self . ports [component ] = {}
440+ if interface not in self . ports [component ]:
441+ self . ports [component ][interface ] = {}
442+ self . ports [component ][interface ][port_name ] = port
464443
465444 def _add_ports (self , component : str , interface : str , ports : Dict [str , Port ]):
466445 "Internally used by a `PackageDef`"
467- if component not in self :
468- self [component ] = {}
469- self [component ][interface ] = ports
446+ if component not in self . ports :
447+ self . ports [component ] = {}
448+ self . ports [component ][interface ] = ports
470449
471450 def get_ports (self , component : str , interface : str ) -> Dict [str , Port ]:
472451 "List the ports allocated in this PortMap for the given `Component` and `Interface`"
473- if component not in self :
452+ if component not in self . ports :
474453 raise KeyError (f"'{ component } ' not found in { self } " )
475- return self [component ][interface ]
476-
477- @classmethod
478- def __get_pydantic_core_schema__ (cls , source_type : Any , handler : GetCoreSchemaHandler ):
479- return core_schema .dict_schema (
480- keys_schema = core_schema .str_schema (),
481- values_schema = core_schema .any_schema ()
482- )
483-
454+ return self .ports [component ][interface ]
484455
485456
486457class LockFile (pydantic .BaseModel ):
0 commit comments