Skip to content

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

@thomthom

Description

@thomthom

gpxpy/gpxpy/gpx.py

Lines 755 to 777 in 09fc46b

def length_2d(self) -> Optional[float]:
"""
Computes 2-dimensional length (meters) of segment (only latitude and
longitude, no elevation).
Returns
----------
length : float
Length returned in meters
"""
return mod_geo.length_2d(self.points) # type: ignore
def length_3d(self) -> float:
"""
Computes 3-dimensional length of segment (latitude, longitude, and
elevation).
Returns
----------
length : float
Length returned in meters
"""
return mod_geo.length_3d(self.points) # type: ignore

Why is length_2d marked as returning Optional[float]?
length_3d does not. GPXTrack and GPX's versions of length_2d are marked as plain float.

Is this a typings bug? Logic didn't seem to suggest that None is possible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions