33import os
44import re
55from io import BufferedIOBase , TextIOBase , TextIOWrapper
6- from typing import List , Dict , Callable , Iterator , Iterable , Tuple , Optional , NamedTuple , IO , cast
6+ from typing import List , Dict , Callable , Iterator , Iterable , Tuple , Optional , NamedTuple , IO , Union , cast
7+
8+
9+ # workaround for https://github.com/python/typeshed/issues/1229
10+ AnyTextIO = Union [TextIOBase , IO [str ]]
11+ AnyBinaryIO = Union [BufferedIOBase , IO [bytes ]]
712
813
914class VPKFileIOWrapper (BufferedIOBase ):
@@ -54,7 +59,7 @@ class VMFFileSystem():
5459 def __init__ (self ) -> None :
5560 self ._dirs : List [str ] = list ()
5661 self ._paks : List [str ] = list ()
57- self ._tree : Dict [str , Callable [[], BufferedIOBase ]] = dict ()
62+ self ._tree : Dict [str , Callable [[], AnyBinaryIO ]] = dict ()
5863
5964 def add_dir (self , path : str ) -> None :
6065 self ._dirs .append (path )
@@ -68,7 +73,7 @@ def add_pak(self, path: str) -> None:
6873 def remove_pak (self , path : str ) -> None :
6974 self ._paks .remove (path )
7075
71- def index_files_iter (self ) -> Iterator [Tuple [str , Callable [[], BufferedIOBase ]]]:
76+ def index_files_iter (self ) -> Iterator [Tuple [str , Callable [[], AnyBinaryIO ]]]:
7277 for directory in self ._dirs :
7378 root : str
7479 files : List [str ]
@@ -89,7 +94,7 @@ def index_files(self) -> None:
8994 def clear_index (self ) -> None :
9095 self ._tree .clear ()
9196
92- def open_file (self , path : str ) -> BufferedIOBase :
97+ def open_file (self , path : str ) -> AnyBinaryIO :
9398 path = path .lower ()
9499 if path not in self ._tree :
95100 raise FileNotFoundError (path )
@@ -154,7 +159,7 @@ def __init__(self, data: vdf.VDFDict, fs: VMFFileSystem):
154159 else :
155160 self .skin = 0
156161
157- def open_model (self ) -> BufferedIOBase :
162+ def open_model (self ) -> AnyBinaryIO :
158163 return self .fs .open_file (self .model )
159164
160165
@@ -385,7 +390,7 @@ def open_sky(self) -> TextIOWrapper:
385390
386391
387392class VMF ():
388- def __init__ (self , file : TextIOBase , data_dirs : Iterable [str ] = [], data_paks : Iterable [str ] = []):
393+ def __init__ (self , file : AnyTextIO , data_dirs : Iterable [str ] = [], data_paks : Iterable [str ] = []):
389394 self .fs = VMFFileSystem ()
390395 for data_dir in data_dirs :
391396 self .fs .add_dir (data_dir )
0 commit comments