Overview
Three sites in PyAutoLens use the typing construct Optional[None] as a default value. Optional[None] evaluates to NoneType — a truthy class object — so these defaults silently pass is not None guards. Behavior today is accidentally harmless (details below), but the code is genuinely wrong and misleading. Found by sweeping all four libraries for siblings of the site flagged during autolens_workspace#411.
Plan
- Replace
plane_index_limit: int = Optional[None] with plane_index_limit: Optional[int] = None in autolens/lens/tracer.py and autolens/lens/tracer_util.py.
- Replace
plane_redshift: float = Optional[None] with plane_redshift: Optional[float] = None in autolens/point/max_separation.py.
- No behavioral change; run the lens + point test suites.
Detailed implementation plan
Affected Repositories
- PyAutoLens (primary, only — sweep of PyAutoGalaxy/PyAutoArray/PyAutoFit found zero further sites)
Branch Survey
| Repository |
Current Branch |
Dirty? |
| ./PyAutoLens |
main |
clean |
In-flight branches (feature/multi-package-rename-multi-dataset, feature/potential-correction-validation) hand-checked: neither touches the three files.
Suggested branch: feature/optional-none-default-typos
Implementation Steps
autolens/lens/tracer.py:250 — plane_index_limit: Optional[int] = None.
autolens/lens/tracer_util.py:178 — same.
autolens/point/max_separation.py:27 — plane_redshift: Optional[float] = None.
python -m pytest test_autolens/lens/ test_autolens/point/.
Why behavior is preserved
tracer_util.traced_grid_2d_list_from guards if plane_index_limit is not None:. The NoneType default passes the guard and compares plane_index == NoneType per plane (always False) — the early exit never fires. With None, the guard is skipped entirely: same result, less accidental work.
SourceMaxSeparation feeds the default to Tracer.plane_index_via_redshift_from, where np.isclose(NoneType, z) raises TypeError, caught to fall back to plane_index = -1. np.isclose(None, z) raises the same TypeError — identical fallback.
Key Files
autolens/lens/tracer.py, autolens/lens/tracer_util.py — multi-plane ray-tracing early-exit parameter.
autolens/point/max_separation.py — point-source max-separation plane selection.
Original Prompt
Click to expand starting prompt
Prompt file: PyAutoMind/active/optional_none_default_typos.md. User instruction: "merge and then fix drift", following the multi-plane-guide-units ship report which flagged this library drift. The notebooks/group/start_here.ipynb regeneration drift is explicitly excluded (picked up by the next generation pass).
Overview
Three sites in PyAutoLens use the typing construct
Optional[None]as a default value.Optional[None]evaluates toNoneType— a truthy class object — so these defaults silently passis not Noneguards. Behavior today is accidentally harmless (details below), but the code is genuinely wrong and misleading. Found by sweeping all four libraries for siblings of the site flagged during autolens_workspace#411.Plan
plane_index_limit: int = Optional[None]withplane_index_limit: Optional[int] = Noneinautolens/lens/tracer.pyandautolens/lens/tracer_util.py.plane_redshift: float = Optional[None]withplane_redshift: Optional[float] = Noneinautolens/point/max_separation.py.Detailed implementation plan
Affected Repositories
Branch Survey
In-flight branches (
feature/multi-package-rename-multi-dataset,feature/potential-correction-validation) hand-checked: neither touches the three files.Suggested branch:
feature/optional-none-default-typosImplementation Steps
autolens/lens/tracer.py:250—plane_index_limit: Optional[int] = None.autolens/lens/tracer_util.py:178— same.autolens/point/max_separation.py:27—plane_redshift: Optional[float] = None.python -m pytest test_autolens/lens/ test_autolens/point/.Why behavior is preserved
tracer_util.traced_grid_2d_list_fromguardsif plane_index_limit is not None:. The NoneType default passes the guard and comparesplane_index == NoneTypeper plane (always False) — the early exit never fires. WithNone, the guard is skipped entirely: same result, less accidental work.SourceMaxSeparationfeeds the default toTracer.plane_index_via_redshift_from, wherenp.isclose(NoneType, z)raisesTypeError, caught to fall back toplane_index = -1.np.isclose(None, z)raises the sameTypeError— identical fallback.Key Files
autolens/lens/tracer.py,autolens/lens/tracer_util.py— multi-plane ray-tracing early-exit parameter.autolens/point/max_separation.py— point-source max-separation plane selection.Original Prompt
Click to expand starting prompt
Prompt file:
PyAutoMind/active/optional_none_default_typos.md. User instruction: "merge and then fix drift", following the multi-plane-guide-units ship report which flagged this library drift. Thenotebooks/group/start_here.ipynbregeneration drift is explicitly excluded (picked up by the next generation pass).