Skip to content

fix: Optional[None] used as default value in tracer + max_separation - #675

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/optional-none-default-typos
Jul 30, 2026
Merged

fix: Optional[None] used as default value in tracer + max_separation#675
Jammy2211 merged 1 commit into
mainfrom
feature/optional-none-default-typos

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Summary

Fixes three sites that used the typing construct Optional[None] as a default value (it evaluates to NoneType, a truthy class object that passes is not None guards):

  • autolens/lens/tracer.pytraced_grid_2d_list_from(..., plane_index_limit: Optional[int] = None)
  • autolens/lens/tracer_util.py — same signature fix in the module-level function
  • autolens/point/max_separation.pySourceMaxSeparation(..., plane_redshift: Optional[float] = None)

Behavior is preserved at all three sites (verified by reading the callees): the tracer's early-exit guard previously ran on every default call but compared plane_index == NoneType (always False), and SourceMaxSeparation's default only worked because np.isclose(NoneType, z) raises the same TypeError that np.isclose(None, z) does, hitting the existing except TypeError fallback to plane_index = -1.

Sweep of PyAutoGalaxy, PyAutoArray and PyAutoFit found no further sites. Found while re-syncing the pedagogical code copies in autolens_workspace#413 (issue #674).

Test Plan

  • python -m pytest test_autolens/lens/ test_autolens/point/ — 200 passed
  • Full CI matrix (3.12 + 3.13)

🤖 Generated with Claude Code

Optional[None] evaluates to NoneType, a truthy class object, so these
defaults silently passed `is not None` guards: the tracer's early-exit
block ran on every default call (comparing plane_index == NoneType, always
False) and SourceMaxSeparation's default only worked because
np.isclose(NoneType, z) raises the TypeError the except clause catches.
A real None preserves behavior at all three sites.

Closes #674

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Jul 30, 2026
@Jammy2211
Jammy2211 merged commit 910651f into main Jul 30, 2026
3 checks passed
@Jammy2211
Jammy2211 deleted the feature/optional-none-default-typos branch July 30, 2026 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pending-release PR queued for the next release build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant