Skip to content

bug(catchment): constructor params typed str | None but crash on None #157

Description

@MAfarrag

Context

PR #149 type-annotated `Catchment.init` and `Calibration.init`
parameters. The type-design-analyzer flagged that three constructor
parameters are annotated `str | None` with non-None defaults, but the
constructor body calls `.lower()` without a None guard.

Problem / Current Behaviour

```python

src/Hapi/catchment.py:58-60

def init(
self,
name,
start,
end,
spatial_resolution: str | None = "Lumped", # annotated | None
temporal_resolution: str | None = "Daily", # annotated | None
routing_method: str | None = "Muskingum", # annotated | None
):
# Line ~89: crashes if None is passed
if spatial_resolution.lower() == "lumped": # AttributeError!
```

Affected locations

File Symbol Notes
`src/Hapi/catchment.py:58-60` `Catchment.init` 3 params
`src/Hapi/calibration.py:41-43` `Calibration.init` Same 3 params

Proposed Solution

Drop `| None` since the constructor doesn't handle None:

```python
spatial_resolution: str = "Lumped",
temporal_resolution: str = "Daily",
routing_method: str = "Muskingum",
```

Effort Estimate

Size: `XS`

Definition of Done

  • Type annotations changed to `str` (no `| None`)
  • Both `Catchment` and `Calibration` updated
  • mypy passes

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions