|
6 | 6 |
|
7 | 7 | from contextlib import closing |
8 | 8 | from pathlib import Path |
9 | | -from typing import Literal, Optional, TYPE_CHECKING, Union, overload |
| 9 | +from typing import Literal, Optional, TYPE_CHECKING, TypeVar, Union, overload |
10 | 10 | from collections.abc import Iterable, Mapping, Sequence |
11 | 11 |
|
12 | 12 | from tableauserverclient.helpers.headers import fix_filename |
|
50 | 50 | FileObject = Union[io.BufferedReader, io.BytesIO] |
51 | 51 | PathOrFile = Union[FilePath, FileObject] |
52 | 52 |
|
53 | | -FilePath = Union[str, os.PathLike] |
54 | 53 | FileObjectR = Union[io.BufferedReader, io.BytesIO] |
55 | 54 | FileObjectW = Union[io.BufferedWriter, io.BytesIO] |
56 | 55 | PathOrFileR = Union[FilePath, FileObjectR] |
@@ -191,16 +190,34 @@ def delete(self, datasource_id: str) -> None: |
191 | 190 | self.delete_request(url) |
192 | 191 | logger.info(f"Deleted single datasource (ID: {datasource_id})") |
193 | 192 |
|
| 193 | + T = TypeVar("T", bound=FileObjectW) |
| 194 | + |
| 195 | + @overload |
| 196 | + def download( |
| 197 | + self, |
| 198 | + datasource_id: str, |
| 199 | + filepath: T, |
| 200 | + include_extract: bool = True, |
| 201 | + ) -> T: ... |
| 202 | + |
| 203 | + @overload |
| 204 | + def download( |
| 205 | + self, |
| 206 | + datasource_id: str, |
| 207 | + filepath: Optional[FilePath] = None, |
| 208 | + include_extract: bool = True, |
| 209 | + ) -> str: ... |
| 210 | + |
194 | 211 | # Download 1 datasource by id |
195 | 212 | @api(version="2.0") |
196 | 213 | @parameter_added_in(no_extract="2.5") |
197 | 214 | @parameter_added_in(include_extract="2.5") |
198 | 215 | def download( |
199 | 216 | self, |
200 | | - datasource_id: str, |
201 | | - filepath: Optional[PathOrFileW] = None, |
202 | | - include_extract: bool = True, |
203 | | - ) -> PathOrFileW: |
| 217 | + datasource_id, |
| 218 | + filepath, |
| 219 | + include_extract=True, |
| 220 | + ): |
204 | 221 | """ |
205 | 222 | Downloads the specified data source from a site. The data source is |
206 | 223 | downloaded as a .tdsx file. |
@@ -479,13 +496,13 @@ def publish( |
479 | 496 | @parameter_added_in(as_job="3.0") |
480 | 497 | def publish( |
481 | 498 | self, |
482 | | - datasource_item: DatasourceItem, |
483 | | - file: PathOrFileR, |
484 | | - mode: str, |
485 | | - connection_credentials: Optional[ConnectionCredentials] = None, |
486 | | - connections: Optional[Sequence[ConnectionItem]] = None, |
487 | | - as_job: bool = False, |
488 | | - ) -> Union[DatasourceItem, JobItem]: |
| 499 | + datasource_item, |
| 500 | + file, |
| 501 | + mode, |
| 502 | + connection_credentials=None, |
| 503 | + connections=None, |
| 504 | + as_job=False, |
| 505 | + ): |
489 | 506 | """ |
490 | 507 | Publishes a data source to a server, or appends data to an existing |
491 | 508 | data source. |
@@ -898,15 +915,35 @@ def _get_datasource_revisions( |
898 | 915 | revisions = RevisionItem.from_response(server_response.content, self.parent_srv.namespace, datasource_item) |
899 | 916 | return revisions |
900 | 917 |
|
901 | | - # Download 1 datasource revision by revision number |
902 | | - @api(version="2.3") |
| 918 | + T = TypeVar("T", bound=FileObjectW) |
| 919 | + |
| 920 | + @overload |
| 921 | + def download_revision( |
| 922 | + self, |
| 923 | + datasource_id: str, |
| 924 | + revision_number: Optional[str], |
| 925 | + filepath: T, |
| 926 | + include_extract: bool = True, |
| 927 | + ) -> T: ... |
| 928 | + |
| 929 | + @overload |
903 | 930 | def download_revision( |
904 | 931 | self, |
905 | 932 | datasource_id: str, |
906 | 933 | revision_number: Optional[str], |
907 | | - filepath: Optional[PathOrFileW] = None, |
| 934 | + filepath: Optional[FilePath] = None, |
908 | 935 | include_extract: bool = True, |
909 | | - ) -> PathOrFileW: |
| 936 | + ) -> str: ... |
| 937 | + |
| 938 | + # Download 1 datasource revision by revision number |
| 939 | + @api(version="2.3") |
| 940 | + def download_revision( |
| 941 | + self, |
| 942 | + datasource_id, |
| 943 | + revision_number, |
| 944 | + filepath, |
| 945 | + include_extract, |
| 946 | + ): |
910 | 947 | """ |
911 | 948 | Downloads a specific version of a data source prior to the current one |
912 | 949 | in .tdsx format. To download the current version of a data source set |
|
0 commit comments