Repository navigation
Description
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]withplane_index_limit: Optional[int] = Noneinautolens/lens/tracer.pyandautolens/lens/tracer_util.py. - Replace
plane_redshift: float = Optional[None]withplane_redshift: Optional[float] = Noneinautolens/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_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. The notebooks/group/start_here.ipynb regeneration drift is explicitly excluded (picked up by the next generation pass).
Activity
Jammy2211 commentedon Jul 30, 2026
Shipped — 2026-07-30
PRs
Summary
Fixed all three
Optional[None]-as-default sites (lens/tracer.py,lens/tracer_util.py,point/max_separation.py) to properOptional[int/float] = Noneannotations. Behavior-preserving, verified against both callees: the tracer's early-exit guard no longer runs pointlessly on default calls, andSourceMaxSeparation'splane_index = -1fallback path is unchanged (np.isclose(None, z)raises the sameTypeErrorthe NoneType class did).test_autolens/lens/ + point/200 passed locally; full CI matrix green.Session Notes
Sweep of PyAutoGalaxy, PyAutoArray and PyAutoFit found zero further sites. Found while re-syncing the pedagogical code copies for autolens_workspace#411/#413.