Skip to content

Commit 52e55b5

Browse files
committed
fix(rtl): fix pyright type errors in wrapper.py
- Handle case where module.__file__ can be None - Properly convert driver c_files/h_files from str to Path - Only pass regs_struct to SoftwareDriverSignature when not None - Cast JsonValue params to int for arithmetic operations Co-developed-by: Claude Code v2.1.12 (claude-opus-4-5-20250929)
1 parent f0e231f commit 52e55b5

1 file changed

Lines changed: 20 additions & 14 deletions

File tree

chipflow/rtl/wrapper.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ def get_source_path(self) -> Path:
7171
return Path(mod.data_location)
7272
elif hasattr(mod, "__path__"):
7373
return Path(mod.__path__[0])
74-
else:
74+
elif mod.__file__ is not None:
7575
return Path(mod.__file__).parent
76+
else:
77+
raise ChipFlowError(f"Module '{self.module}' has no file path")
7678
except ImportError as e:
7779
raise ChipFlowError(f"Could not import module '{self.module}': {e}")
7880
raise ChipFlowError("No source path available")
@@ -811,19 +813,23 @@ def __init__(self, config: ExternalWrapConfig, verilog_files: List[Path] | None
811813
wishbone_ports[port_name] = port_config
812814

813815
# Use SoftwareDriverSignature if driver config is provided
814-
if config.driver:
816+
if config.driver and config.driver.regs_struct:
815817
try:
816818
from chipflow.platform import SoftwareDriverSignature
817819

818-
super().__init__(
819-
SoftwareDriverSignature(
820-
members=signature_members,
821-
component=self,
822-
regs_struct=config.driver.regs_struct,
823-
c_files=config.driver.c_files,
824-
h_files=config.driver.h_files,
825-
)
826-
)
820+
# Build kwargs with proper types
821+
driver_kwargs: dict = {
822+
"members": signature_members,
823+
"component": self,
824+
"regs_struct": config.driver.regs_struct,
825+
}
826+
# Convert string paths to Path objects
827+
if config.driver.c_files:
828+
driver_kwargs["c_files"] = [Path(f) for f in config.driver.c_files]
829+
if config.driver.h_files:
830+
driver_kwargs["h_files"] = [Path(f) for f in config.driver.h_files]
831+
832+
super().__init__(SoftwareDriverSignature(**driver_kwargs))
827833
except ImportError:
828834
# Fallback if chipflow.platform not available
829835
super().__init__(signature_members)
@@ -835,9 +841,9 @@ def __init__(self, config: ExternalWrapConfig, verilog_files: List[Path] | None
835841
for port_name, port_config in wishbone_ports.items():
836842
port = getattr(self, port_name)
837843
params = port_config.params or {}
838-
addr_width = params.get("addr_width", 4)
839-
data_width = params.get("data_width", 32)
840-
granularity = params.get("granularity", 8)
844+
addr_width = int(params.get("addr_width", 4)) # type: ignore[arg-type]
845+
data_width = int(params.get("data_width", 32)) # type: ignore[arg-type]
846+
granularity = int(params.get("granularity", 8)) # type: ignore[arg-type]
841847

842848
# Memory map addr_width includes byte addressing
843849
# = interface addr_width + log2(data_width/granularity)

0 commit comments

Comments
 (0)