2020import time
2121import zipfile
2222from datetime import date
23+ from os import PathLike
2324from struct import Struct , calcsize , error , pack , unpack
2425from types import TracebackType
2526from typing import (
@@ -159,7 +160,7 @@ def read(self, size: int = -1) -> bytes: ...
159160
160161
161162# File name, file object or anything with a read() method that returns bytes.
162- BinaryFileT = Union [str , IO [bytes ]]
163+ BinaryFileT = Union [str , PathLike [ Any ], IO [bytes ]]
163164BinaryFileStreamT = Union [IO [bytes ], io .BytesIO , WriteSeekableBinStream ]
164165
165166FieldTypeT = Literal ["C" , "D" , "F" , "L" , "M" , "N" ]
@@ -341,11 +342,11 @@ class GeoJSONFeatureCollectionWithBBox(GeoJSONFeatureCollection):
341342
342343
343344@overload
344- def fsdecode_if_pathlike (path : os . PathLike [Any ]) -> str : ...
345+ def fsdecode_if_pathlike (path : PathLike [Any ]) -> str : ...
345346@overload
346347def fsdecode_if_pathlike (path : T ) -> T : ...
347348def fsdecode_if_pathlike (path : Any ) -> Any :
348- if isinstance (path , os . PathLike ):
349+ if isinstance (path , PathLike ):
349350 return os .fsdecode (path ) # str
350351
351352 return path
@@ -2243,7 +2244,7 @@ def _assert_ext_is_supported(self, ext: str) -> None:
22432244
22442245 def __init__ (
22452246 self ,
2246- shapefile_path : Union [str , os . PathLike [Any ]] = "" ,
2247+ shapefile_path : Union [str , PathLike [Any ]] = "" ,
22472248 / ,
22482249 * ,
22492250 encoding : str = "utf-8" ,
@@ -2411,7 +2412,7 @@ def __init__(
24112412 return
24122413
24132414 if shp is not _NO_SHP_SENTINEL :
2414- shp = cast (Union [str , IO [bytes ], None ], shp )
2415+ shp = cast (Union [str , PathLike [ Any ], IO [bytes ], None ], shp )
24152416 self .shp = self .__seek_0_on_file_obj_wrap_or_open_from_name ("shp" , shp )
24162417 self .shx = self .__seek_0_on_file_obj_wrap_or_open_from_name ("shx" , shx )
24172418
@@ -2432,7 +2433,7 @@ def __seek_0_on_file_obj_wrap_or_open_from_name(
24322433 if file_ is None :
24332434 return None
24342435
2435- if isinstance (file_ , str ):
2436+ if isinstance (file_ , ( str , PathLike ) ):
24362437 baseName , __ = os .path .splitext (file_ )
24372438 return self ._load_constituent_file (baseName , ext )
24382439
@@ -3235,7 +3236,7 @@ class Writer:
32353236
32363237 def __init__ (
32373238 self ,
3238- target : Union [str , os . PathLike [Any ], None ] = None ,
3239+ target : Union [str , PathLike [Any ], None ] = None ,
32393240 shapeType : Optional [int ] = None ,
32403241 autoBalance : bool = False ,
32413242 * ,
0 commit comments