|
7 | 7 | from contextlib import ExitStack
|
8 | 8 | from dataclasses import dataclass
|
9 | 9 | from pathlib import Path
|
10 |
| -from typing import IO, TYPE_CHECKING, BinaryIO, Union |
| 10 | +from typing import IO, TYPE_CHECKING, BinaryIO, Literal, Union, overload |
11 | 11 |
|
12 | 12 | from fs import open_fs
|
13 | 13 | from fs.copy import copy_dir, copy_file, copy_fs
|
@@ -185,11 +185,23 @@ def save(self, file: BinaryIO, include: list[str] | None = None, exclude: list[s
|
185 | 185 |
|
186 | 186 | tar_fs.writetext("fs.json", json.dumps(fs_index))
|
187 | 187 |
|
188 |
| - def get(self, fs_name: str) -> VirtualFileSystem: |
| 188 | + @overload |
| 189 | + def get(self, fs_name: str) -> VirtualFileSystem: ... |
| 190 | + |
| 191 | + @overload |
| 192 | + def get(self, fs_name: str, create_if_missing: Literal[True]) -> VirtualFileSystem: ... |
| 193 | + |
| 194 | + @overload |
| 195 | + def get(self, fs_name: str, create_if_missing: Literal[False]) -> VirtualFileSystem | None: ... |
| 196 | + |
| 197 | + def get(self, fs_name: str, create_if_missing: bool = True) -> VirtualFileSystem | None: |
189 | 198 | if fs_name in self._filesystems:
|
190 | 199 | logging.debug("Get FS from collection: %s", fs_name)
|
191 | 200 | return self._filesystems[fs_name]
|
192 | 201 |
|
| 202 | + if not create_if_missing: |
| 203 | + return None |
| 204 | + |
193 | 205 | logging.debug("Create new VFS: %s", fs_name)
|
194 | 206 | fs = VirtualFileSystem()
|
195 | 207 | self._filesystems[fs_name] = fs
|
|
0 commit comments