Skip to content

Fix GPXTrackSegment.length_2d return annotation - #302

Merged
tkrajina merged 1 commit into
tkrajina:devfrom
saitakarcesme:codex/correct-segment-length-return-type
Sep 26, 2026
Merged

tkrajina merged 1 commit into
tkrajina:devfrom
saitakarcesme:codex/correct-segment-length-return-type

Conversation

@saitakarcesme

Copy link
Copy Markdown
Contributor

GPXTrackSegment.length_2d() delegates to geo.length_2d(), which always returns a number, including zero for empty or single-point segments. Its Optional[float] annotation nevertheless prevents callers from using that result as a float without a None check. Change it to float, matching the implementation and the track/GPX length methods.

Fixes #286.

The regression test uses explicitly typed assignments for empty, single-point, and two-point segments, and checks the returned distances. All three assignments fail mypy before the annotation fix and pass afterward.

Validation on Python 3.13.5:

  • All 150 unit tests pass with lxml 6.1.3, and again with the standard-library XML backend.
  • gpxinfo runs successfully on all GPX fixtures; git diff --check passes.
  • Full strict mypy 2.3.1 reports 19 pre-existing diagnostics. Comparing before/after output shows only the three regression diagnostics removed and no added diagnostics.

Prepared and tested using OpenAI Codex; no human review is claimed.

@tkrajina
tkrajina merged commit dfc48e2 into tkrajina:dev Sep 26, 2026
@tkrajina

Copy link
Copy Markdown
Owner

Merged, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GPXTrackSegment's length_2d marked as Optional[float] - can it ever return None?

2 participants