1919import zipfile
2020from datetime import date
2121from struct import Struct , calcsize , error , pack , unpack
22- from typing import Iterable , Iterator , Optional
22+ from typing import Any , Iterable , Iterator , Optional , Union
2323from urllib .error import HTTPError
2424from urllib .parse import urlparse , urlunparse
2525from urllib .request import Request , urlopen
9292NODATA = - 10e38 # as per the ESRI shapefile spec, only used for m-values.
9393
9494
95- def b (v , encoding = "utf-8" , encodingErrors = "strict" ):
95+ def b (
96+ v : Union [str , bytes ], encoding : str = "utf-8" , encodingErrors : str = "strict"
97+ ) -> bytes :
9698 if isinstance (v , str ):
9799 # For python 3 encode str to bytes.
98100 return v .encode (encoding , encodingErrors )
@@ -107,7 +109,9 @@ def b(v, encoding="utf-8", encodingErrors="strict"):
107109 return str (v ).encode (encoding , encodingErrors )
108110
109111
110- def u (v , encoding = "utf-8" , encodingErrors = "strict" ):
112+ def u (
113+ v : Union [str , bytes ], encoding : str = "utf-8" , encodingErrors : str = "strict"
114+ ) -> str :
111115 if isinstance (v , bytes ):
112116 # For python 3 decode bytes to str.
113117 return v .decode (encoding , encodingErrors )
@@ -122,11 +126,11 @@ def u(v, encoding="utf-8", encodingErrors="strict"):
122126 return bytes (v ).decode (encoding , encodingErrors )
123127
124128
125- def is_string (v ) :
129+ def is_string (v : Any ) -> bool :
126130 return isinstance (v , str )
127131
128132
129- def pathlike_obj (path ) :
133+ def pathlike_obj (path : Any ) -> Any :
130134 if isinstance (path , os .PathLike ):
131135 return os .fsdecode (path )
132136 else :
0 commit comments