Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Aimeryyy opened this issue Nov 9, 2023 · 1 comment
Closed

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

Aimeryyy opened this issue Nov 9, 2023 · 1 comment

Comments

@Aimeryyy
Copy link

Aimeryyy commented Nov 9, 2023

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
        ...
@tkrajina
Copy link
Owner

Fair point. Fixed now in dev.

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

No branches or pull requests

2 participants