Skip to content

Commit 5d83a53

Browse files
committed
Chore: Reduce the need to manually update the output from stubgen, by defining the types of objects that confuse it, and flag as Incomplete
1 parent 013dd40 commit 5d83a53

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

src/shapefile.py

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@
4646
from urllib.request import Request, urlopen
4747

4848
# Create named logger
49-
logger = logging.getLogger(__name__)
49+
logger: logging.Logger = logging.getLogger(__name__)
5050

5151
# Module settings
5252
VERBOSE = True
5353

5454
# Test config (for the Doctest runner and test_shapefile.py)
55-
REPLACE_REMOTE_URLS_WITH_LOCALHOST = (
55+
REPLACE_REMOTE_URLS_WITH_LOCALHOST: bool = (
5656
os.getenv("REPLACE_REMOTE_URLS_WITH_LOCALHOST", "").lower() == "yes"
5757
)
5858

@@ -72,7 +72,7 @@
7272
MULTIPOINTM = 28
7373
MULTIPATCH = 31
7474

75-
SHAPETYPE_LOOKUP = {
75+
SHAPETYPE_LOOKUP: dict[int, str] = {
7676
NULL: "NULL",
7777
POINT: "POINT",
7878
POLYLINE: "POLYLINE",
@@ -89,7 +89,9 @@
8989
MULTIPATCH: "MULTIPATCH",
9090
}
9191

92-
SHAPETYPENUM_LOOKUP = {name: code for code, name in SHAPETYPE_LOOKUP.items()}
92+
SHAPETYPENUM_LOOKUP: dict[str, int] = {
93+
name: code for code, name in SHAPETYPE_LOOKUP.items()
94+
}
9395

9496
TRIANGLE_STRIP = 0
9597
TRIANGLE_FAN = 1
@@ -98,7 +100,7 @@
98100
FIRST_RING = 4
99101
RING = 5
100102

101-
PARTTYPE_LOOKUP = {
103+
PARTTYPE_LOOKUP: dict[int, str] = {
102104
0: "TRIANGLE_STRIP",
103105
1: "TRIANGLE_FAN",
104106
2: "OUTER_RING",
@@ -159,6 +161,8 @@ def read(self, size: int = -1) -> bytes: ...
159161

160162
FieldTypeT = Literal["C", "D", "F", "L", "M", "N"]
161163

164+
ShapeTypesMarkerSetT = frozenset[int]
165+
162166

163167
# https://en.wikipedia.org/wiki/.dbf#Database_records
164168
class FieldType:
@@ -329,7 +333,10 @@ class GeoJSONFeatureCollectionWithBBox(GeoJSONFeatureCollection):
329333

330334
# Helpers
331335

332-
MISSING = (None, "") # Don't make a set, as user input may not be Hashable
336+
MISSING: tuple[None, str] = (
337+
None,
338+
"",
339+
) # Don't make a set, as user input may not be Hashable
333340
NODATA = -10e38 # as per the ESRI shapefile spec, only used for m-values.
334341

335342
unpack_2_int32_be = Struct(">2i").unpack
@@ -1101,7 +1108,7 @@ def write_to_byte_stream(
11011108
return 0
11021109

11031110

1104-
_CanHaveBBox_shapeTypes = frozenset(
1111+
_CanHaveBBox_shapeTypes: ShapeTypesMarkerSetT = frozenset(
11051112
[
11061113
POLYLINE,
11071114
POLYLINEM,
@@ -1268,7 +1275,7 @@ def write_to_byte_stream(
12681275
return n
12691276

12701277

1271-
_CanHaveParts_shapeTypes = frozenset(
1278+
_CanHaveParts_shapeTypes: ShapeTypesMarkerSetT = frozenset(
12721279
[
12731280
POLYLINE,
12741281
POLYLINEM,
@@ -1308,7 +1315,7 @@ def _write_part_indices_to_byte_stream(
13081315
return b_io.write(pack(f"<{len(s.parts)}i", *s.parts))
13091316

13101317

1311-
Point_shapeTypes = frozenset([POINT, POINTM, POINTZ])
1318+
Point_shapeTypes: ShapeTypesMarkerSetT = frozenset([POINT, POINTM, POINTZ])
13121319

13131320

13141321
class Point(Shape):
@@ -1387,7 +1394,7 @@ def write_to_byte_stream(b_io: WriteableBinStream, s: Shape, i: int) -> int:
13871394
return n
13881395

13891396

1390-
Polyline_shapeTypes = frozenset([POLYLINE, POLYLINEM, POLYLINEZ])
1397+
Polyline_shapeTypes: ShapeTypesMarkerSetT = frozenset([POLYLINE, POLYLINEM, POLYLINEZ])
13911398

13921399

13931400
class Polyline(_CanHaveParts):
@@ -1419,7 +1426,7 @@ def __init__(
14191426
)
14201427

14211428

1422-
Polygon_shapeTypes = frozenset([POLYGON, POLYGONM, POLYGONZ])
1429+
Polygon_shapeTypes: ShapeTypesMarkerSetT = frozenset([POLYGON, POLYGONM, POLYGONZ])
14231430

14241431

14251432
class Polygon(_CanHaveParts):
@@ -1443,7 +1450,9 @@ def __init__(
14431450
)
14441451

14451452

1446-
MultiPoint_shapeTypes = frozenset([MULTIPOINT, MULTIPOINTM, MULTIPOINTZ])
1453+
MultiPoint_shapeTypes: ShapeTypesMarkerSetT = frozenset(
1454+
[MULTIPOINT, MULTIPOINTM, MULTIPOINTZ]
1455+
)
14471456

14481457

14491458
class MultiPoint(_CanHaveBBox):
@@ -1473,7 +1482,7 @@ def __init__(
14731482

14741483

14751484
# Not a PointM or a PointZ
1476-
_HasM_shapeTypes = frozenset(
1485+
_HasM_shapeTypes: ShapeTypesMarkerSetT = frozenset(
14771486
[
14781487
POLYLINEM,
14791488
POLYLINEZ,
@@ -1538,7 +1547,7 @@ def _write_ms_to_byte_stream(
15381547

15391548

15401549
# Not a PointZ
1541-
_HasZ_shapeTypes = frozenset(
1550+
_HasZ_shapeTypes: ShapeTypesMarkerSetT = frozenset(
15421551
[
15431552
POLYLINEZ,
15441553
POLYGONZ,
@@ -1584,7 +1593,7 @@ def _write_zs_to_byte_stream(
15841593
return num_bytes_written
15851594

15861595

1587-
MultiPatch_shapeTypes = frozenset([MULTIPATCH])
1596+
MultiPatch_shapeTypes: ShapeTypesMarkerSetT = frozenset([MULTIPATCH])
15881597

15891598

15901599
class MultiPatch(_HasM, _HasZ, _CanHaveParts):
@@ -1636,7 +1645,7 @@ def _write_part_types_to_byte_stream(b_io: WriteableBinStream, s: Shape) -> int:
16361645
return b_io.write(pack(f"<{len(s.partTypes)}i", *s.partTypes))
16371646

16381647

1639-
PointM_shapeTypes = frozenset([POINTM, POINTZ])
1648+
PointM_shapeTypes: ShapeTypesMarkerSetT = frozenset([POINTM, POINTZ])
16401649

16411650

16421651
class PointM(Point):
@@ -1683,7 +1692,7 @@ def _write_single_point_m_to_byte_stream(
16831692
return b_io.write(pack("<1d", m_to_encode))
16841693

16851694

1686-
PolylineM_shapeTypes = frozenset([POLYLINEM, POLYLINEZ])
1695+
PolylineM_shapeTypes: ShapeTypesMarkerSetT = frozenset([POLYLINEM, POLYLINEZ])
16871696

16881697

16891698
class PolylineM(Polyline, _HasM):
@@ -1719,7 +1728,7 @@ def __init__(
17191728
)
17201729

17211730

1722-
PolygonM_shapeTypes = frozenset([POLYGONM, POLYGONZ])
1731+
PolygonM_shapeTypes: ShapeTypesMarkerSetT = frozenset([POLYGONM, POLYGONZ])
17231732

17241733

17251734
class PolygonM(Polygon, _HasM):
@@ -1755,7 +1764,7 @@ def __init__(
17551764
)
17561765

17571766

1758-
MultiPointM_shapeTypes = frozenset([MULTIPOINTM, MULTIPOINTZ])
1767+
MultiPointM_shapeTypes: ShapeTypesMarkerSetT = frozenset([MULTIPOINTM, MULTIPOINTZ])
17591768

17601769

17611770
class MultiPointM(MultiPoint, _HasM):
@@ -1788,7 +1797,7 @@ def __init__(
17881797
)
17891798

17901799

1791-
PointZ_shapeTypes = frozenset([POINTZ])
1800+
PointZ_shapeTypes: ShapeTypesMarkerSetT = frozenset([POINTZ])
17921801

17931802

17941803
class PointZ(PointM):
@@ -1828,7 +1837,7 @@ def _write_single_point_z_to_byte_stream(
18281837
return b_io.write(pack("<d", z))
18291838

18301839

1831-
PolylineZ_shapeTypes = frozenset([POLYLINEZ])
1840+
PolylineZ_shapeTypes: ShapeTypesMarkerSetT = frozenset([POLYLINEZ])
18321841

18331842

18341843
class PolylineZ(PolylineM, _HasZ):
@@ -1868,7 +1877,7 @@ def __init__(
18681877
)
18691878

18701879

1871-
PolygonZ_shapeTypes = frozenset([POLYGONZ])
1880+
PolygonZ_shapeTypes: ShapeTypesMarkerSetT = frozenset([POLYGONZ])
18721881

18731882

18741883
class PolygonZ(PolygonM, _HasZ):
@@ -1908,7 +1917,7 @@ def __init__(
19081917
)
19091918

19101919

1911-
MultiPointZ_shapeTypes = frozenset([MULTIPOINTZ])
1920+
MultiPointZ_shapeTypes: ShapeTypesMarkerSetT = frozenset([MULTIPOINTZ])
19121921

19131922

19141923
class MultiPointZ(MultiPointM, _HasZ):

0 commit comments

Comments
 (0)