Skip to content

Commit 4261839

Browse files
committed
Replace #type: ignores with casts or otherwise remove
1 parent 5cf41f2 commit 4261839

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

src/shapefile.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ class GeoJSONFeatureCollectionWithBBox(GeoJSONFeatureCollection):
394394
ARR_TYPE = TypeVar("ARR_TYPE", int, float)
395395

396396

397-
class _Array(array.array, Generic[ARR_TYPE]): # type: ignore[type-arg]
397+
class _Array(array.array[ARR_TYPE]):
398398
"""Converts python tuples to lists of the appropriate type.
399399
Used to unpack different shapefile header parts."""
400400

@@ -2102,10 +2102,10 @@ def __getitem__(
21022102
:return: the value of the field
21032103
"""
21042104
try:
2105-
return list.__getitem__(self, item) # type: ignore[index]
2105+
return list.__getitem__(self, cast(SupportsIndex | slice, item))
21062106
except TypeError:
21072107
try:
2108-
index = self.__field_positions[item] # type: ignore[index]
2108+
index = self.__field_positions[cast(str, item)]
21092109
except KeyError:
21102110
index = None
21112111
if index is not None:
@@ -2132,12 +2132,17 @@ def __setitem__(
21322132
:param key: Either the position of the value or the name of a field
21332133
:param value: the new value of the field
21342134
"""
2135+
ValidKVTuple = (
2136+
tuple[SupportsIndex, RecordValue] | tuple[slice, Iterable[RecordValue]]
2137+
)
21352138
try:
2136-
return list.__setitem__(self, key, value) # type: ignore[misc,assignment]
2139+
list.__setitem__(self, *cast(ValidKVTuple, (key, value)))
2140+
return
21372141
except TypeError:
2138-
index = self.__field_positions.get(key) # type: ignore[arg-type]
2142+
index = self.__field_positions.get(cast(str, key))
21392143
if index is not None:
2140-
return list.__setitem__(self, index, value) # type: ignore[misc]
2144+
list.__setitem__(self, index, cast(RecordValue, value))
2145+
return
21412146

21422147
raise IndexError(f"{key} is not a field name and not an int")
21432148

@@ -3733,7 +3738,7 @@ def iterShapeRecords(
37333738
):
37343739
yield ShapeRecord(shape=shape, record=record)
37353740
else:
3736-
# only iterate where shape.bbox overlaps with the given bbox
3741+
# Only yield ShapeRecords whose shape.bbox overlaps with bbox.
37373742
# TODO: internal _record method should be faster but would have to
37383743
# make sure to seek to correct file location...
37393744

0 commit comments

Comments
 (0)