@@ -653,10 +653,8 @@ def __geo_interface__(self) -> GeoJSONHomogeneousGeometryObject:
653653 # the geojson spec does not define a proper null-geometry type
654654 # however, it does allow geometry types with 'empty' coordinates to be interpreted as null-geometries
655655 return {"type" : "Point" , "coordinates" : ()}
656- # return {"type": "Point", "coordinates": tuple()} #type: ignore
657656
658657 return {"type" : "Point" , "coordinates" : self .points [0 ]}
659- # return {"type": "Point", "coordinates": tuple(self.points[0])} # type: ignore
660658
661659 if self .shapeType in [MULTIPOINT , MULTIPOINTM , MULTIPOINTZ ]:
662660 if len (self .points ) == 0 :
@@ -669,7 +667,6 @@ def __geo_interface__(self) -> GeoJSONHomogeneousGeometryObject:
669667 return {
670668 "type" : "MultiPoint" ,
671669 "coordinates" : self .points ,
672- # "coordinates": [tuple(p) for p in self.points], #type: ignore
673670 }
674671
675672 if self .shapeType in [POLYLINE , POLYLINEM , POLYLINEZ ]:
@@ -684,7 +681,6 @@ def __geo_interface__(self) -> GeoJSONHomogeneousGeometryObject:
684681 return {
685682 "type" : "LineString" ,
686683 "coordinates" : self .points ,
687- # "coordinates": [tuple(p) for p in self.points], #type: ignore
688684 }
689685
690686 # multilinestring
@@ -695,11 +691,9 @@ def __geo_interface__(self) -> GeoJSONHomogeneousGeometryObject:
695691 ps = part
696692 continue
697693
698- # coordinates.append([tuple(p) for p in self.points[ps:part]])
699694 coordinates .append (list (self .points [ps :part ]))
700695 ps = part
701696
702- # coordinates.append([tuple(p) for p in self.points[part:]])
703697 # assert len(self.parts) >1 # so disable pylint rule
704698 coordinates .append (list (self .points [part :])) # pylint: disable=undefined-loop-variable
705699 return {"type" : "MultiLineString" , "coordinates" : coordinates }
@@ -713,16 +707,14 @@ def __geo_interface__(self) -> GeoJSONHomogeneousGeometryObject:
713707
714708 # get all polygon rings
715709 rings = []
716- for i in range ( len ( self .parts ) ):
710+ for i , start in enumerate ( self .parts ):
717711 # get indexes of start and end points of the ring
718- start = self .parts [i ]
719712 try :
720713 end = self .parts [i + 1 ]
721714 except IndexError :
722715 end = len (self .points )
723716
724717 # extract the points that make up the ring
725- # ring = [tuple(p) for p in self.points[start:end]]
726718 ring = list (self .points [start :end ])
727719 rings .append (ring )
728720
@@ -2076,7 +2068,8 @@ def __shape(
20762068
20772069 # next_shape = f.tell() + recLength_bytes
20782070
2079- # Read entire record into memory
2071+ # Read entire record into memory to avoid having to call
2072+ # seek on the file afterwards
20802073 b_io = io .BytesIO (f .read (recLength_bytes ))
20812074 b_io .seek (0 )
20822075
@@ -2363,7 +2356,7 @@ def __record(
23632356 # parse each value
23642357 record = []
23652358 for (__name , typ , __size , deci ), value in zip (fieldTuples , recordContents ):
2366- if typ in ( "N" , "F" ) :
2359+ if typ in { "N" , "F" } :
23672360 # numeric or float: number stored as a string, right justified, and padded with blanks to the width of the field.
23682361 value = value .split (b"\0 " )[0 ]
23692362 value = value .replace (b"*" , b"" ) # QGIS NULL is all '*' chars
@@ -2687,9 +2680,7 @@ def close(self):
26872680
26882681 # Flush files
26892682 for attribute in (self .shp , self .shx , self .dbf ):
2690- if hasattr (attribute , "flush" ) and not (
2691- hasattr (attribute , "closed" ) and attribute .closed
2692- ):
2683+ if hasattr (attribute , "flush" ) and not getattr (attribute , "closed" , False ):
26932684 try :
26942685 attribute .flush ()
26952686 except OSError :
0 commit comments