Skip to content

Commit 73d225c

Browse files
jacalataclaude
andcommitted
feat: consolidate and export public type aliases from tableauserverclient.types
HyperAction*, FilePath, FileObject*, PathOrFile*, AddResponse, IDPAttributes, IDPProperty, and HasIdpConfigurationID were defined locally in endpoint files (in some cases duplicated across 4 files) but not importable from the top-level package. Users annotating calls to update_hyper_data(), publish(), download(), add_to_schedule(), or OIDC methods had to import from internal modules. Move all shared type aliases to tableauserverclient/types.py and re-export from tableauserverclient/__init__.py. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 0c27808 commit 73d225c

8 files changed

Lines changed: 127 additions & 87 deletions

File tree

tableauserverclient/__init__.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,24 @@
5858
WorkbookItem,
5959
)
6060

61+
from tableauserverclient.types import (
62+
AddResponse,
63+
FilePath,
64+
FileObject,
65+
FileObjectR,
66+
FileObjectW,
67+
HasIdpConfigurationID,
68+
HyperAction,
69+
HyperActionCondition,
70+
HyperActionRow,
71+
HyperActionTable,
72+
IDPAttributes,
73+
IDPProperty,
74+
PathOrFile,
75+
PathOrFileR,
76+
PathOrFileW,
77+
)
78+
6179
from tableauserverclient.server import (
6280
CSVRequestOptions,
6381
ExcelRequestOptions,
@@ -76,6 +94,7 @@
7694
)
7795

7896
__all__ = [
97+
"AddResponse",
7998
"BackgroundJobItem",
8099
"CollectionItem",
81100
"ColumnItem",
@@ -96,13 +115,24 @@
96115
"FailedSignInError",
97116
"FavoriteItem",
98117
"FileuploadItem",
118+
"FilePath",
119+
"FileObject",
120+
"FileObjectR",
121+
"FileObjectW",
99122
"Filter",
100123
"FlowItem",
101124
"FlowRunItem",
102125
"get_versions",
103126
"GroupItem",
104127
"GroupSetItem",
128+
"HasIdpConfigurationID",
105129
"HourlyInterval",
130+
"HyperAction",
131+
"HyperActionCondition",
132+
"HyperActionRow",
133+
"HyperActionTable",
134+
"IDPAttributes",
135+
"IDPProperty",
106136
"ImageRequestOptions",
107137
"IntervalItem",
108138
"JobItem",
@@ -122,6 +152,9 @@
122152
"Permission",
123153
"PermissionsRule",
124154
"PersonalAccessTokenAuth",
155+
"PathOrFile",
156+
"PathOrFileR",
157+
"PathOrFileW",
125158
"ProjectItem",
126159
"RequestOptions",
127160
"Resource",

tableauserverclient/server/endpoint/custom_views_endpoint.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,8 @@
3232
update the name or owner of a custom view.
3333
"""
3434

35-
FilePath = str | os.PathLike
36-
FileObject = io.BufferedReader | io.BytesIO
37-
FileObjectR = io.BufferedReader | io.BytesIO
38-
FileObjectW = io.BufferedWriter | io.BytesIO
39-
PathOrFileR = FilePath | FileObjectR
40-
PathOrFileW = FilePath | FileObjectW
35+
from tableauserverclient.types import FilePath, FileObject, FileObjectR, FileObjectW, PathOrFileR, PathOrFileW
36+
4137
io_types_r = (io.BufferedReader, io.BytesIO)
4238
io_types_w = (io.BufferedWriter, io.BytesIO)
4339

tableauserverclient/server/endpoint/datasources_endpoint.py

Lines changed: 15 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,29 @@
66

77
from contextlib import closing
88
from pathlib import Path
9-
from typing import Literal, TYPE_CHECKING, TypedDict, TypeVar, overload
9+
from typing import Literal, TYPE_CHECKING, TypeVar, overload
1010
from collections.abc import Iterable, Sequence
1111

1212
from tableauserverclient.models.dqw_item import DQWItem
1313
from tableauserverclient.server.query import QuerySet
14+
from tableauserverclient.types import (
15+
FilePath,
16+
FileObject,
17+
FileObjectR,
18+
FileObjectW,
19+
PathOrFile,
20+
PathOrFileR,
21+
PathOrFileW,
22+
HyperAction,
23+
HyperActionCondition,
24+
HyperActionRow,
25+
HyperActionTable,
26+
AddResponse,
27+
)
1428

1529
if TYPE_CHECKING:
1630
from tableauserverclient.server import Server
1731
from tableauserverclient.models import PermissionsRule
18-
from .schedules_endpoint import AddResponse
1932

2033
from tableauserverclient.server.endpoint.dqw_endpoint import _DataQualityWarningEndpoint
2134
from tableauserverclient.server.endpoint.endpoint import QuerysetEndpoint, api, parameter_added_in
@@ -50,53 +63,6 @@
5063
io_types_r = (io.BytesIO, io.BufferedReader)
5164
io_types_w = (io.BytesIO, io.BufferedWriter)
5265

53-
FilePath = str | os.PathLike
54-
FileObject = io.BufferedReader | io.BytesIO
55-
PathOrFile = FilePath | FileObject
56-
57-
FileObjectR = io.BufferedReader | io.BytesIO
58-
FileObjectW = io.BufferedWriter | io.BytesIO
59-
PathOrFileR = FilePath | FileObjectR
60-
PathOrFileW = FilePath | FileObjectW
61-
62-
63-
HyperActionCondition = TypedDict(
64-
"HyperActionCondition",
65-
{
66-
"op": str,
67-
"target-col": str,
68-
"source-col": str,
69-
},
70-
)
71-
72-
HyperActionRow = TypedDict(
73-
"HyperActionRow",
74-
{
75-
"action": Literal[
76-
"update",
77-
"upsert",
78-
"delete",
79-
],
80-
"source-table": str,
81-
"target-table": str,
82-
"condition": HyperActionCondition,
83-
},
84-
)
85-
86-
HyperActionTable = TypedDict(
87-
"HyperActionTable",
88-
{
89-
"action": Literal[
90-
"insert",
91-
"replace",
92-
],
93-
"source-table": str,
94-
"target-table": str,
95-
},
96-
)
97-
98-
HyperAction = HyperActionTable | HyperActionRow
99-
10066

10167
_UNSET = object()
10268

tableauserverclient/server/endpoint/flows_endpoint.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,12 @@
4141

4242
from tableauserverclient.helpers.logging import logger
4343

44+
from tableauserverclient.types import FilePath, FileObjectR, FileObjectW, PathOrFileR, PathOrFileW, AddResponse
45+
4446
if TYPE_CHECKING:
4547
from tableauserverclient.models import DQWItem
4648
from tableauserverclient.models.permissions_item import PermissionsRule
4749
from tableauserverclient.server.request_options import RequestOptions
48-
from tableauserverclient.server.endpoint.schedules_endpoint import AddResponse
49-
50-
51-
FilePath = str | os.PathLike
52-
FileObjectR = io.BufferedReader | io.BytesIO
53-
FileObjectW = io.BufferedWriter | io.BytesIO
54-
PathOrFileR = FilePath | FileObjectR
55-
PathOrFileW = FilePath | FileObjectW
5650

5751

5852
class Flows(QuerysetEndpoint[FlowItem], TaggingMixin[FlowItem]):

tableauserverclient/server/endpoint/oidc_endpoint.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
1-
from typing import Protocol, Union, TYPE_CHECKING
1+
from typing import TYPE_CHECKING
22
from tableauserverclient.models.oidc_item import SiteOIDCConfiguration
33
from tableauserverclient.server.endpoint import Endpoint
44
from tableauserverclient.server.request_factory import RequestFactory
55
from tableauserverclient.server.endpoint.endpoint import api
6+
from tableauserverclient.types import IDPAttributes, IDPProperty, HasIdpConfigurationID
67

78
if TYPE_CHECKING:
89
from tableauserverclient.models.site_item import SiteAuthConfiguration
910
from tableauserverclient.server.server import Server
1011

1112

12-
class IDPAttributes(Protocol):
13-
idp_configuration_id: str
14-
15-
16-
class IDPProperty(Protocol):
17-
@property
18-
def idp_configuration_id(self) -> str: ...
19-
20-
21-
HasIdpConfigurationID = str | IDPAttributes
22-
23-
2413
class OIDC(Endpoint):
2514
def __init__(self, server: "Server") -> None:
2615
self.parent_srv = server

tableauserverclient/server/endpoint/schedules_endpoint.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22
import copy
33
import logging
44
import warnings
5-
from collections import namedtuple
65
from typing import TYPE_CHECKING, Any, Callable, Literal, overload
76

87
from .endpoint import Endpoint, api, parameter_added_in
98
from .exceptions import MissingRequiredFieldError
109
from tableauserverclient.server import RequestFactory
1110
from tableauserverclient.models import PaginationItem, ScheduleItem, TaskItem, ExtractItem
1211
from tableauserverclient.models.schedule_item import parse_batch_schedule_state
12+
from tableauserverclient.types import AddResponse
1313

1414
from tableauserverclient.helpers.logging import logger
1515

16-
AddResponse = namedtuple("AddResponse", ("result", "error", "warnings", "task_created"))
1716
OK = AddResponse(result=True, error=None, warnings=None, task_created=None)
1817

1918
if TYPE_CHECKING:

tableauserverclient/server/endpoint/workbooks_endpoint.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,20 @@
4040
)
4141
from collections.abc import Iterable, Sequence
4242

43+
from tableauserverclient.types import (
44+
FilePath,
45+
FileObject,
46+
FileObjectR,
47+
FileObjectW,
48+
PathOrFileR,
49+
PathOrFileW,
50+
AddResponse,
51+
)
52+
4353
if TYPE_CHECKING:
4454
from tableauserverclient.server import Server
4555
from tableauserverclient.server.request_options import RequestOptions, PDFRequestOptions, PPTXRequestOptions
4656
from tableauserverclient.models import DatasourceItem
47-
from tableauserverclient.server.endpoint.schedules_endpoint import AddResponse
4857

4958
io_types_r = (io.BytesIO, io.BufferedReader)
5059
io_types_w = (io.BytesIO, io.BufferedWriter)
@@ -56,14 +65,6 @@
5665

5766
from tableauserverclient.helpers.logging import logger
5867

59-
FilePath = str | os.PathLike
60-
FileObject = io.BufferedReader | io.BytesIO
61-
FileObjectR = io.BufferedReader | io.BytesIO
62-
FileObjectW = io.BufferedWriter | io.BytesIO
63-
PathOrFileR = FilePath | FileObjectR
64-
PathOrFileW = FilePath | FileObjectW
65-
66-
6768
_UNSET = object()
6869

6970

tableauserverclient/types.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import io
2+
import os
3+
from collections import namedtuple
4+
from typing import Literal, Protocol, TypedDict
5+
6+
# File path and object type aliases used across publish/download methods
7+
FilePath = str | os.PathLike
8+
FileObject = io.BufferedReader | io.BytesIO
9+
FileObjectR = io.BufferedReader | io.BytesIO
10+
FileObjectW = io.BufferedWriter | io.BytesIO
11+
PathOrFile = FilePath | FileObject
12+
PathOrFileR = FilePath | FileObjectR
13+
PathOrFileW = FilePath | FileObjectW
14+
15+
16+
# Hyper action types for Datasources.update_hyper_data()
17+
HyperActionCondition = TypedDict(
18+
"HyperActionCondition",
19+
{
20+
"op": str,
21+
"target-col": str,
22+
"source-col": str,
23+
},
24+
)
25+
26+
HyperActionRow = TypedDict(
27+
"HyperActionRow",
28+
{
29+
"action": Literal["update", "upsert", "delete"],
30+
"source-table": str,
31+
"target-table": str,
32+
"condition": HyperActionCondition,
33+
},
34+
)
35+
36+
HyperActionTable = TypedDict(
37+
"HyperActionTable",
38+
{
39+
"action": Literal["insert", "replace"],
40+
"source-table": str,
41+
"target-table": str,
42+
},
43+
)
44+
45+
HyperAction = HyperActionTable | HyperActionRow
46+
47+
48+
# Return type for Schedules.add_to_schedule()
49+
AddResponse = namedtuple("AddResponse", ("result", "error", "warnings", "task_created"))
50+
51+
52+
# IDP types for OIDC endpoint
53+
class IDPAttributes(Protocol):
54+
idp_configuration_id: str
55+
56+
57+
class IDPProperty(Protocol):
58+
@property
59+
def idp_configuration_id(self) -> str: ...
60+
61+
62+
HasIdpConfigurationID = str | IDPAttributes

0 commit comments

Comments
 (0)