tkrajina / gpxpy

gpx-py is a python GPX parser. GPX (GPS eXchange Format) is an XML based file format for GPS tracks.
Apache License 2.0
989 stars 223 forks source link

Bug: `free variable 'from_start_to_end' referenced before assignment in enclosing scope` #231

Closed martinlehoux closed 1 year ago

martinlehoux commented 3 years ago

GPXpy: 1.4.2 Python: 3.8.3

Issue

I ran the following line:

gpx = gpxpy.parse(self.source_file.open())

and encountered the following issue:

free variable 'from_start_to_end' referenced before assignment in enclosing scope

Ideas

The following line seems to have an issue (at least I ran into one): https://github.com/tkrajina/gpxpy/blob/e3733bbd59d11bcbf089f30b286286fcd728bb46/gpxpy/gpx.py#L1112

The few lines above do not define from_start_to_end when dist is falsy

dist = interval[-1].distance_3d(end)
if dist:
    from_start_to_end = distances[-1] + dist

Maybe default to 0 ?

martinlehoux commented 3 years ago

Here is the failing track, I can open it successfully in gnome-maps track.zip