tkrajina/gpxpy

[newbie] Wrong return type on GPXTrackSegment.get_duration()

Closed this issue · 1 comments

Function get_duration() from GPXTrackSegment must return float | None and returns int.

import gpxpy
import gpxpy.gpx

gpx_content = """<?xml version="1.0" encoding="UTF-8"?>
    <gpx version="1.1">
        <trk>
            <name>Test Track</name>
            <trkseg>
            </trkseg>
        </trk>
    </gpx>
    """

gpx = gpxpy.parse(gpx_content)
# Take the first segment of the first route
segment = gpx.tracks[0].segments[0]
print(type(segment.get_duration())) # int instead of float

Actual code:

def get_duration(self) -> Optional[float]:
        """
        Calculates duration or track segment

        Returns
        -------
        duration: float
            Duration in seconds
        """
        if not self.points or len(self.points) < 2:
            return 0
        ...

Suggested:

def get_duration(self) -> Optional[float]:
        """
        Calculates duration or track segment

        Returns
        -------
        duration: float
            Duration in seconds
        """
        if not self.points or len(self.points) < 2:
            return 0.0 # instead of 0
        ...

Fair point. Fixed now in dev.