Skip to content

Commit 024fd2f

Browse files
committed
1 parent ca46fe4 commit 024fd2f

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

‎stubs/vdf/__init__.pyi‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, AnyStr, Callable, TypeVar, Type
1+
from typing import Any, AnyStr, Callable, TypeVar, Type, Union, IO
22
from io import TextIOBase
33
from vdf.vdict import VDFDict as VDFDict
44

@@ -8,13 +8,15 @@ BOMS: str
88

99
# waiting for https://github.com/python/mypy/issues/731
1010
T = TypeVar("T", bound=dict)
11+
# workaround for https://github.com/python/typeshed/issues/1229
12+
AnyTextIO = Union[TextIOBase, IO[str]]
1113

1214
def strip_bom(line: AnyStr) -> AnyStr: ...
13-
def parse(fp: TextIOBase, mapper: Type[T] = ..., merge_duplicate_keys: bool = ..., escaped: bool = ...) -> T: ...
15+
def parse(fp: AnyTextIO, mapper: Type[T] = ..., merge_duplicate_keys: bool = ..., escaped: bool = ...) -> T: ...
1416
def loads(s: str, mapper: Type[T] = ..., merge_duplicate_keys: bool = ..., escaped: bool = ...) -> T: ...
15-
def load(fp: TextIOBase, mapper: Type[T] = ..., merge_duplicate_keys: bool = ..., escaped: bool = ...) -> T: ...
17+
def load(fp: AnyTextIO, mapper: Type[T] = ..., merge_duplicate_keys: bool = ..., escaped: bool = ...) -> T: ...
1618
def dumps(obj: dict, pretty: bool = ..., escaped: bool = ...) -> str: ...
17-
def dump(obj: dict, fp: TextIOBase, pretty: bool = ..., escaped: bool = ...) -> None: ...
19+
def dump(obj: dict, fp: AnyTextIO, pretty: bool = ..., escaped: bool = ...) -> None: ...
1820

1921
class BASE_INT(int_type): ...
2022
class UINT_64(BASE_INT): ...

‎vmfpy/__init__.py‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
import os
44
import re
55
from 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

914
class 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

387392
class 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

Comments
 (0)