Skip to content

Commit d61efde

Browse files
committed
chore: replace Union with modern syntax
1 parent ec0614e commit d61efde

27 files changed

+156
-160
lines changed

tableauserverclient/models/favorites_item.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class FavoriteType(TypedDict):
2525

2626
class FavoriteItem:
2727
@classmethod
28-
def from_response(cls, xml: Union[str, bytes], namespace: dict) -> FavoriteType:
28+
def from_response(cls, xml: str | bytes, namespace: dict) -> FavoriteType:
2929
favorites: FavoriteType = {
3030
"collections": [],
3131
"datasources": [],

tableauserverclient/models/schedule_item.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from requests import Response
2121

2222

23-
Interval = Union[HourlyInterval, DailyInterval, WeeklyInterval, MonthlyInterval]
23+
Interval = HourlyInterval | DailyInterval | WeeklyInterval | MonthlyInterval
2424

2525

2626
class ScheduleItem:

tableauserverclient/models/site_item.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ def __init__(
154154
notify_site_admins_on_throttle: bool = False,
155155
authoring_enabled: bool = True,
156156
custom_subscription_email_enabled: bool = False,
157-
custom_subscription_email: Union[str, bool] = False,
157+
custom_subscription_email: str | bool = False,
158158
custom_subscription_footer_enabled: bool = False,
159-
custom_subscription_footer: Union[str, bool] = False,
159+
custom_subscription_footer: str | bool = False,
160160
ask_data_mode: str = "EnabledByDefault",
161161
named_sharing_enabled: bool = True,
162162
mobile_biometrics_enabled: bool = False,
@@ -555,11 +555,11 @@ def custom_subscription_email_enabled(self, value: bool) -> None:
555555
self._custom_subscription_email_enabled = value
556556

557557
@property
558-
def custom_subscription_email(self) -> Union[str, bool]:
558+
def custom_subscription_email(self) -> str | bool:
559559
return self._custom_subscription_email
560560

561561
@custom_subscription_email.setter
562-
def custom_subscription_email(self, value: Union[str, bool]):
562+
def custom_subscription_email(self, value: str | bool):
563563
self._custom_subscription_email = value
564564

565565
@property
@@ -572,11 +572,11 @@ def custom_subscription_footer_enabled(self, value: bool) -> None:
572572
self._custom_subscription_footer_enabled = value
573573

574574
@property
575-
def custom_subscription_footer(self) -> Union[str, bool]:
575+
def custom_subscription_footer(self) -> str | bool:
576576
return self._custom_subscription_footer
577577

578578
@custom_subscription_footer.setter
579-
def custom_subscription_footer(self, value: Union[str, bool]) -> None:
579+
def custom_subscription_footer(self, value: str | bool) -> None:
580580
self._custom_subscription_footer = value
581581

582582
@property

tableauserverclient/models/tableau_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Resource:
4040
]
4141

4242

43-
def plural_type(content_type: Union[Resource, str]) -> str:
43+
def plural_type(content_type: Resource | str) -> str:
4444
if content_type == Resource.Lens:
4545
return "lenses"
4646
else:

tableauserverclient/server/endpoint/custom_views_endpoint.py

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

35-
FilePath = Union[str, os.PathLike]
36-
FileObject = Union[io.BufferedReader, io.BytesIO]
37-
FileObjectR = Union[io.BufferedReader, io.BytesIO]
38-
FileObjectW = Union[io.BufferedWriter, io.BytesIO]
39-
PathOrFileR = Union[FilePath, FileObjectR]
40-
PathOrFileW = Union[FilePath, FileObjectW]
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
4141
io_types_r = (io.BufferedReader, io.BytesIO)
4242
io_types_w = (io.BufferedWriter, io.BytesIO)
4343

tableauserverclient/server/endpoint/data_alert_endpoint.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def get_by_id(self, dataAlert_id: str) -> DataAlertItem:
4444
return DataAlertItem.from_response(server_response.content, self.parent_srv.namespace)[0]
4545

4646
@api(version="3.2")
47-
def delete(self, dataAlert: Union[DataAlertItem, str]) -> None:
47+
def delete(self, dataAlert: DataAlertItem | str) -> None:
4848
if isinstance(dataAlert, DataAlertItem):
4949
dataAlert_id = dataAlert.id
5050
elif isinstance(dataAlert, str):
@@ -60,7 +60,7 @@ def delete(self, dataAlert: Union[DataAlertItem, str]) -> None:
6060
logger.info(f"Deleted single dataAlert (ID: {dataAlert_id})")
6161

6262
@api(version="3.2")
63-
def delete_user_from_alert(self, dataAlert: Union[DataAlertItem, str], user: Union[UserItem, str]) -> None:
63+
def delete_user_from_alert(self, dataAlert: DataAlertItem | str, user: UserItem | str) -> None:
6464
if isinstance(dataAlert, DataAlertItem):
6565
dataAlert_id = dataAlert.id
6666
elif isinstance(dataAlert, str):
@@ -85,7 +85,7 @@ def delete_user_from_alert(self, dataAlert: Union[DataAlertItem, str], user: Uni
8585
logger.info(f"Deleted User (ID {user_id}) from dataAlert (ID: {dataAlert_id})")
8686

8787
@api(version="3.2")
88-
def add_user_to_alert(self, dataAlert_item: DataAlertItem, user: Union[UserItem, str]) -> UserItem:
88+
def add_user_to_alert(self, dataAlert_item: DataAlertItem, user: UserItem | str) -> UserItem:
8989
if isinstance(user, UserItem):
9090
user_id = user.id
9191
elif isinstance(user, str):

tableauserverclient/server/endpoint/databases_endpoint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,11 @@ def delete_dqw(self, item: DatabaseItem) -> None:
211211
self._data_quality_warnings.clear(item)
212212

213213
@api(version="3.9")
214-
def add_tags(self, item: Union[DatabaseItem, str], tags: Iterable[str]) -> set[str]:
214+
def add_tags(self, item: DatabaseItem | str, tags: Iterable[str]) -> set[str]:
215215
return super().add_tags(item, tags)
216216

217217
@api(version="3.9")
218-
def delete_tags(self, item: Union[DatabaseItem, str], tags: Iterable[str]) -> None:
218+
def delete_tags(self, item: DatabaseItem | str, tags: Iterable[str]) -> None:
219219
super().delete_tags(item, tags)
220220

221221
@api(version="3.9")

tableauserverclient/server/endpoint/datasources_endpoint.py

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@
4646
io_types_r = (io.BytesIO, io.BufferedReader)
4747
io_types_w = (io.BytesIO, io.BufferedWriter)
4848

49-
FilePath = Union[str, os.PathLike]
50-
FileObject = Union[io.BufferedReader, io.BytesIO]
51-
PathOrFile = Union[FilePath, FileObject]
49+
FilePath = str | os.PathLike
50+
FileObject = io.BufferedReader | io.BytesIO
51+
PathOrFile = FilePath | FileObject
5252

53-
FileObjectR = Union[io.BufferedReader, io.BytesIO]
54-
FileObjectW = Union[io.BufferedWriter, io.BytesIO]
55-
PathOrFileR = Union[FilePath, FileObjectR]
56-
PathOrFileW = Union[FilePath, FileObjectW]
53+
FileObjectR = io.BufferedReader | io.BytesIO
54+
FileObjectW = io.BufferedWriter | io.BytesIO
55+
PathOrFileR = FilePath | FileObjectR
56+
PathOrFileW = FilePath | FileObjectW
5757

5858

5959
HyperActionCondition = TypedDict(
@@ -91,7 +91,7 @@
9191
},
9292
)
9393

94-
HyperAction = Union[HyperActionTable, HyperActionRow]
94+
HyperAction = HyperActionTable | HyperActionRow
9595

9696

9797
class Datasources(QuerysetEndpoint[DatasourceItem], TaggingMixin[DatasourceItem]):
@@ -430,7 +430,7 @@ def update_connections(
430430
return connection_items
431431

432432
@api(version="2.8")
433-
def refresh(self, datasource_item: Union[DatasourceItem, str], incremental: bool = False) -> JobItem:
433+
def refresh(self, datasource_item: DatasourceItem | str, incremental: bool = False) -> JobItem:
434434
"""
435435
Refreshes the extract of an existing workbook.
436436
@@ -542,47 +542,47 @@ def publish(
542542
as_job=False,
543543
):
544544
"""
545-
Publishes a data source to a server, or appends data to an existing
546-
data source.
545+
Publishes a data source to a server, or appends data to an existing
546+
data source.
547547
548-
This method checks the size of the data source and automatically
549-
determines whether the publish the data source in multiple parts or in
550-
one operation.
548+
This method checks the size of the data source and automatically
549+
determines whether the publish the data source in multiple parts or in
550+
one operation.
551551
552-
REST API: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_data_sources.htm#publish_data_source
552+
REST API: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_data_sources.htm#publish_data_source
553553
554-
Parameters
555-
----------
556-
datasource_item : DatasourceItem
557-
The datasource item to publish. The fields for name and project_id
558-
are required.
554+
Parameters
555+
----------
556+
datasource_item : DatasourceItem
557+
The datasource item to publish. The fields for name and project_id
558+
are required.
559559
560-
file : PathOrFileR
561-
The file path or file object to publish.
560+
file : PathOrFileR
561+
The file path or file object to publish.
562562
563-
mode : str
564-
Specifies whether you are publishing a new datasource (CreateNew),
565-
overwriting an existing datasource (Overwrite), or add to an
566-
existing datasource (Append). You can also use the publish mode
567-
attributes, for example: TSC.Server.PublishMode.Overwrite.
563+
mode : str
564+
Specifies whether you are publishing a new datasource (CreateNew),
565+
overwriting an existing datasource (Overwrite), or add to an
566+
existing datasource (Append). You can also use the publish mode
567+
attributes, for example: TSC.Server.PublishMode.Overwrite.
568568
569-
connection_credentials : Optional[ConnectionCredentials]
570-
The connection credentials to use when publishing the datasource.
571-
Mutually exclusive with the connections parameter.
569+
connection_credentials : Optional[ConnectionCredentials]
570+
The connection credentials to use when publishing the datasource.
571+
Mutually exclusive with the connections parameter.
572572
573-
connections : Optional[Sequence[ConnectionItem]]
574-
The connections to use when publishing the datasource. Mutually
575-
exclusive with the connection_credentials parameter.
573+
connections : Optional[Sequence[ConnectionItem]]
574+
The connections to use when publishing the datasource. Mutually
575+
exclusive with the connection_credentials parameter.
576576
577-
as_job : bool, default False
578-
If True, the publish operation is asynchronous and returns a job
579-
item. If False, the publish operation is synchronous and returns a
580-
datasource item.
577+
as_job : bool, default False
578+
If True, the publish operation is asynchronous and returns a job
579+
item. If False, the publish operation is synchronous and returns a
580+
datasource item.
581581
582-
Returns
583-
-------
584-
Union[DatasourceItem, JobItem]
585-
The datasource item or job item.
582+
Returns
583+
-------
584+
DatasourceItem | JobItem
585+
The datasource item or job item.
586586
587587
"""
588588
if isinstance(file, (os.PathLike, str)):
@@ -683,7 +683,7 @@ def publish(
683683
@api(version="3.13")
684684
def update_hyper_data(
685685
self,
686-
datasource_or_connection_item: Union[DatasourceItem, ConnectionItem, str],
686+
datasource_or_connection_item: DatasourceItem | ConnectionItem | str,
687687
*,
688688
request_id: str,
689689
actions: Sequence[HyperAction],
@@ -705,7 +705,7 @@ def update_hyper_data(
705705
706706
Parameters
707707
----------
708-
datasource_or_connection_item : Union[DatasourceItem, ConnectionItem, str]
708+
datasource_or_connection_item : DatasourceItem | ConnectionItem | str
709709
The datasource item, connection item, or datasource ID. Either a
710710
DataSourceItem or a ConnectionItem. If the datasource only contains
711711
a single connection, the DataSourceItem is sufficient to identify
@@ -1099,18 +1099,18 @@ def schedule_extract_refresh(
10991099
return self.parent_srv.schedules.add_to_schedule(schedule_id, datasource=item)
11001100

11011101
@api(version="1.0")
1102-
def add_tags(self, item: Union[DatasourceItem, str], tags: Union[Iterable[str], str]) -> set[str]:
1102+
def add_tags(self, item: DatasourceItem | str, tags: Iterable[str] | str) -> set[str]:
11031103
"""
11041104
Adds one or more tags to the specified datasource item.
11051105
11061106
REST API: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_data_sources.htm#add_tags_to_data_source
11071107
11081108
Parameters
11091109
----------
1110-
item : Union[DatasourceItem, str]
1110+
item : DatasourceItem | str
11111111
The datasource item or ID to add tags to.
11121112
1113-
tags : Union[Iterable[str], str]
1113+
tags : Iterable[str] | str
11141114
The tag or tags to add to the datasource item.
11151115
11161116
Returns
@@ -1121,18 +1121,18 @@ def add_tags(self, item: Union[DatasourceItem, str], tags: Union[Iterable[str],
11211121
return super().add_tags(item, tags)
11221122

11231123
@api(version="1.0")
1124-
def delete_tags(self, item: Union[DatasourceItem, str], tags: Union[Iterable[str], str]) -> None:
1124+
def delete_tags(self, item: DatasourceItem | str, tags: Iterable[str] | str) -> None:
11251125
"""
11261126
Deletes one or more tags from the specified datasource item.
11271127
11281128
REST API: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_data_sources.htm#delete_tag_from_data_source
11291129
11301130
Parameters
11311131
----------
1132-
item : Union[DatasourceItem, str]
1132+
item : DatasourceItem | str
11331133
The datasource item or ID to delete tags from.
11341134
1135-
tags : Union[Iterable[str], str]
1135+
tags : Iterable[str] | str
11361136
The tag or tags to delete from the datasource item.
11371137
11381138
Returns

tableauserverclient/server/endpoint/default_permissions_endpoint.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from tableauserverclient.helpers.logging import logger
1515

1616
# these are the only two items that can hold default permissions for another type
17-
BaseItem = Union[DatabaseItem, ProjectItem]
17+
BaseItem = DatabaseItem | ProjectItem
1818

1919

2020
class _DefaultPermissionsEndpoint(Endpoint):
@@ -39,7 +39,7 @@ def __str__(self):
3939
__repr__ = __str__
4040

4141
def update_default_permissions(
42-
self, resource: BaseItem, permissions: Sequence[PermissionsRule], content_type: Union[Resource, str]
42+
self, resource: BaseItem, permissions: Sequence[PermissionsRule], content_type: Resource | str
4343
) -> list[PermissionsRule]:
4444
url = f"{self.owner_baseurl()}/{resource.id}/default-permissions/{plural_type(content_type)}"
4545
update_req = RequestFactory.Permission.add_req(permissions)
@@ -51,7 +51,7 @@ def update_default_permissions(
5151
return permissions
5252

5353
def delete_default_permission(
54-
self, resource: BaseItem, rule: PermissionsRule, content_type: Union[Resource, str]
54+
self, resource: BaseItem, rule: PermissionsRule, content_type: Resource | str
5555
) -> None:
5656
for capability, mode in rule.capabilities.items():
5757
# Made readability better but line is too long, will make this look better
@@ -74,7 +74,7 @@ def delete_default_permission(
7474

7575
logger.info(f"Deleted permission for {rule.grantee.tag_name} {rule.grantee.id} item {resource.id}")
7676

77-
def populate_default_permissions(self, item: BaseItem, content_type: Union[Resource, str]) -> None:
77+
def populate_default_permissions(self, item: BaseItem, content_type: Resource | str) -> None:
7878
if not item.id:
7979
error = "Server item is missing ID. Item must be retrieved from server first."
8080
raise MissingRequiredFieldError(error)
@@ -86,7 +86,7 @@ def permission_fetcher() -> list[PermissionsRule]:
8686
logger.info(f"Populated default {content_type} permissions for item (ID: {item.id})")
8787

8888
def _get_default_permissions(
89-
self, item: BaseItem, content_type: Union[Resource, str], req_options: Optional["RequestOptions"] = None
89+
self, item: BaseItem, content_type: Resource | str, req_options: "RequestOptions | None" = None
9090
) -> list[PermissionsRule]:
9191
url = f"{self.owner_baseurl()}/{item.id}/default-permissions/{plural_type(content_type)}"
9292
server_response = self.get_request(url, req_options)

tableauserverclient/server/endpoint/endpoint.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def set_user_agent(parameters):
8787
# return explicitly for testing only
8888
return parameters
8989

90-
def _blocking_request(self, method, url, parameters={}) -> Optional[Union["Response", Exception]]:
90+
def _blocking_request(self, method, url, parameters={}) -> "Response | Exception | None":
9191
response = None
9292
logger.debug(f"[{datetime.timestamp()}] Begin blocking request to {url}")
9393
try:
@@ -100,7 +100,7 @@ def _blocking_request(self, method, url, parameters={}) -> Optional[Union["Respo
100100

101101
def send_request_while_show_progress_threaded(
102102
self, method, url, parameters={}, request_timeout=None
103-
) -> Optional[Union["Response", Exception]]:
103+
) -> "Response | Exception | None":
104104
return self._blocking_request(method, url, parameters)
105105

106106
def _make_request(
@@ -125,7 +125,7 @@ def _make_request(
125125
# a request can, for stuff like publishing, spin for ages waiting for a response.
126126
# we need some user-facing activity so they know it's not dead.
127127
request_timeout = self.parent_srv.http_options.get("timeout") or 0
128-
server_response: Optional[Union["Response", Exception]] = self.send_request_while_show_progress_threaded(
128+
server_response: "Response | Exception | None" = self.send_request_while_show_progress_threaded(
129129
method, url, parameters, request_timeout
130130
)
131131
logger.debug(f"[{datetime.timestamp()}] Async request returned: received {server_response}")

0 commit comments

Comments
 (0)