Skip to content

Commit 95acef4

Browse files
robtaylorclaude
andcommitted
Add type annotations to _allocate() abstract method
Make BasePackageDef generic over pin type (PinType) and add proper type annotations to the _allocate() abstract method. This fixes pyright type checking errors where the return type was treated as None instead of List[PinType]. Changes: - BasePackageDef now inherits from Generic[PinType] - LinearAllocPackageDef specifies BasePackageDef[int] - GAPackageDef specifies BasePackageDef[GAPin] - _allocate() signature includes proper type hints 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 31ceb99 commit 95acef4

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed
-16 KB
Binary file not shown.

chipflow_lib/packaging/base.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import abc
1111
from collections import defaultdict
12-
from typing import TYPE_CHECKING, Dict, List, Set
12+
from typing import TYPE_CHECKING, Dict, Generic, List, Set, TypeVar
1313

1414
import pydantic
1515
from amaranth.lib import wiring, io
@@ -24,8 +24,11 @@
2424
if TYPE_CHECKING:
2525
from ..config_models import Config, Process
2626

27+
# Type variable for pin types (int for linear allocation, GAPin for grid arrays, etc.)
28+
PinType = TypeVar('PinType')
2729

28-
class BasePackageDef(pydantic.BaseModel, abc.ABC):
30+
31+
class BasePackageDef(pydantic.BaseModel, Generic[PinType], abc.ABC):
2932
"""
3033
Abstract base class for the definition of a package.
3134
@@ -166,7 +169,7 @@ def allocate_pins(self, config: 'Config', process: 'Process', lockfile: LockFile
166169
return LockFile(package=package, process=process, metadata=self._interfaces, port_map=portmap)
167170

168171
@abc.abstractmethod
169-
def _allocate(self, available, width: int):
172+
def _allocate(self, available: Set[PinType], width: int) -> List[PinType]:
170173
"""
171174
Allocate pins from available set.
172175
@@ -206,7 +209,7 @@ def _sortpins(self, pins: Pins) -> PinList:
206209
return sorted(list(pins))
207210

208211

209-
class LinearAllocPackageDef(BasePackageDef):
212+
class LinearAllocPackageDef(BasePackageDef[int]):
210213
"""
211214
Base class for package types with linear pin/pad allocation.
212215

chipflow_lib/packaging/grid_array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class GALayout(StrEnum):
3636
ISLAND = auto() # Perimeter + center island
3737

3838

39-
class GAPackageDef(BasePackageDef):
39+
class GAPackageDef(BasePackageDef[GAPin]):
4040
"""
4141
Definition of a grid array package.
4242

0 commit comments

Comments
 (0)