Skip to content

Commit e52dc55

Browse files
committed
Use Union instead of |
1 parent 1f38277 commit e52dc55

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/shapefile.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,7 +2102,9 @@ def __getitem__(
21022102
:return: the value of the field
21032103
"""
21042104
try:
2105-
return list.__getitem__(self, cast(SupportsIndex | slice, item))
2105+
# Using | on types in Python 3.9 also raises TypeError, so Union needed.
2106+
# as we subsequently catch TypeError
2107+
return list.__getitem__(self, cast(Union[SupportsIndex, slice], item))
21062108
except TypeError:
21072109
try:
21082110
index = self.__field_positions[cast(str, item)]
@@ -2132,9 +2134,11 @@ def __setitem__(
21322134
:param key: Either the position of the value or the name of a field
21332135
:param value: the new value of the field
21342136
"""
2135-
ValidKVTuple = (
2136-
tuple[SupportsIndex, RecordValue] | tuple[slice, Iterable[RecordValue]]
2137-
)
2137+
# Using | on types in Python 3.9 also raises TypeError, so Union needed.
2138+
# as we subsequently catch TypeError
2139+
ValidKVTuple = Union[
2140+
tuple[SupportsIndex, RecordValue], tuple[slice, Iterable[RecordValue]]
2141+
]
21382142
try:
21392143
list.__setitem__(self, *cast(ValidKVTuple, (key, value)))
21402144
return

0 commit comments

Comments
 (0)