Skip to content

Commit 4da8203

Browse files
committed
Type hint Writer."shape" methods
1 parent 243a3ac commit 4da8203

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

src/shapefile.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2801,57 +2801,53 @@ def multipoint(self, points: Coords):
28012801
# nest the points inside a list to be compatible with the generic shapeparts method
28022802
self._shapeparts(parts=[points], shapeType=shapeType)
28032803

2804-
def multipointm(self, points):
2804+
def multipointm(self, points: list[PointM]):
28052805
"""Creates a MULTIPOINTM shape.
28062806
Points is a list of xym values.
28072807
If the m (measure) value is not included, it defaults to None (NoData)."""
28082808
shapeType = MULTIPOINTM
2809-
points = [
2810-
points
2811-
] # nest the points inside a list to be compatible with the generic shapeparts method
2812-
self._shapeparts(parts=points, shapeType=shapeType)
2809+
# nest the points inside a list to be compatible with the generic shapeparts method
2810+
self._shapeparts(parts=[points], shapeType=shapeType)
28132811

28142812
def multipointz(self, points):
28152813
"""Creates a MULTIPOINTZ shape.
28162814
Points is a list of xyzm values.
28172815
If the z (elevation) value is not included, it defaults to 0.
28182816
If the m (measure) value is not included, it defaults to None (NoData)."""
28192817
shapeType = MULTIPOINTZ
2820-
points = [
2821-
points
2822-
] # nest the points inside a list to be compatible with the generic shapeparts method
2823-
self._shapeparts(parts=points, shapeType=shapeType)
2818+
# nest the points inside a list to be compatible with the generic shapeparts method
2819+
self._shapeparts(parts=[points], shapeType=shapeType)
28242820

2825-
def line(self, lines: Collection[Coords]):
2821+
def line(self, lines: list[Coords]):
28262822
"""Creates a POLYLINE shape.
28272823
Lines is a collection of lines, each made up of a list of xy values."""
28282824
shapeType = POLYLINE
28292825
self._shapeparts(parts=lines, shapeType=shapeType)
28302826

2831-
def linem(self, lines):
2827+
def linem(self, lines: list[Points]):
28322828
"""Creates a POLYLINEM shape.
28332829
Lines is a collection of lines, each made up of a list of xym values.
28342830
If the m (measure) value is not included, it defaults to None (NoData)."""
28352831
shapeType = POLYLINEM
28362832
self._shapeparts(parts=lines, shapeType=shapeType)
28372833

2838-
def linez(self, lines):
2834+
def linez(self, lines: list[Points]):
28392835
"""Creates a POLYLINEZ shape.
28402836
Lines is a collection of lines, each made up of a list of xyzm values.
28412837
If the z (elevation) value is not included, it defaults to 0.
28422838
If the m (measure) value is not included, it defaults to None (NoData)."""
28432839
shapeType = POLYLINEZ
28442840
self._shapeparts(parts=lines, shapeType=shapeType)
28452841

2846-
def poly(self, polys: Collection[Coords]):
2842+
def poly(self, polys: list[Coords]):
28472843
"""Creates a POLYGON shape.
28482844
Polys is a collection of polygons, each made up of a list of xy values.
28492845
Note that for ordinary polygons the coordinates must run in a clockwise direction.
28502846
If some of the polygons are holes, these must run in a counterclockwise direction."""
28512847
shapeType = POLYGON
28522848
self._shapeparts(parts=polys, shapeType=shapeType)
28532849

2854-
def polym(self, polys):
2850+
def polym(self, polys: list[Points]):
28552851
"""Creates a POLYGONM shape.
28562852
Polys is a collection of polygons, each made up of a list of xym values.
28572853
Note that for ordinary polygons the coordinates must run in a clockwise direction.
@@ -2860,7 +2856,7 @@ def polym(self, polys):
28602856
shapeType = POLYGONM
28612857
self._shapeparts(parts=polys, shapeType=shapeType)
28622858

2863-
def polyz(self, polys):
2859+
def polyz(self, polys: list[Points]):
28642860
"""Creates a POLYGONZ shape.
28652861
Polys is a collection of polygons, each made up of a list of xyzm values.
28662862
Note that for ordinary polygons the coordinates must run in a clockwise direction.
@@ -2870,7 +2866,7 @@ def polyz(self, polys):
28702866
shapeType = POLYGONZ
28712867
self._shapeparts(parts=polys, shapeType=shapeType)
28722868

2873-
def multipatch(self, parts, partTypes):
2869+
def multipatch(self, parts: list[list[PointZ]], partTypes: list[int]):
28742870
"""Creates a MULTIPATCH shape.
28752871
Parts is a collection of 3D surface patches, each made up of a list of xyzm values.
28762872
PartTypes is a list of types that define each of the surface patches.
@@ -2886,11 +2882,12 @@ def multipatch(self, parts, partTypes):
28862882
# set part index position
28872883
polyShape.parts.append(len(polyShape.points))
28882884
# add points
2889-
for point in part:
2890-
# Ensure point is list
2891-
if not isinstance(point, list):
2892-
point = list(point)
2893-
polyShape.points.append(point)
2885+
# for point in part:
2886+
# # Ensure point is list
2887+
# if not isinstance(point, list):
2888+
# point = list(point)
2889+
# polyShape.points.append(point)
2890+
polyShape.points.extend(part)
28942891
polyShape.partTypes = partTypes
28952892
# write the shape
28962893
self.shape(polyShape)

0 commit comments

Comments
 (0)