From 5e826237715720523f370eeab98a5a0854f4266f Mon Sep 17 00:00:00 2001 From: Jordan Woods <13803242+jorwoods@users.noreply.github.com> Date: Wed, 4 Sep 2024 06:50:32 -0500 Subject: [PATCH 1/4] chore(typing): include samples in type checks Including the sample scripts in type checking will allow more thorough testing to validate the samples work as expected, as well as more testing around how a library consumer may use the library. --- pyproject.toml | 2 +- samples/explore_favorites.py | 6 +++--- samples/list.py | 3 +++ tableauserverclient/models/favorites_item.py | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3bf47ea23..f506808db 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,7 +46,7 @@ disable_error_code = [ # tableauserverclient\server\endpoint\datasources_endpoint.py:48: error: Cannot assign multiple types to name "FilePath" without an explicit "Type[...]" annotation [misc] 'annotation-unchecked' # can be removed when check_untyped_defs = true ] -files = ["tableauserverclient", "test"] +files = ["tableauserverclient", "test", "samples"] show_error_codes = true ignore_missing_imports = true # defusedxml library has no types no_implicit_reexport = true diff --git a/samples/explore_favorites.py b/samples/explore_favorites.py index 243e91954..46389e916 100644 --- a/samples/explore_favorites.py +++ b/samples/explore_favorites.py @@ -3,7 +3,7 @@ import argparse import logging import tableauserverclient as TSC -from tableauserverclient import Resource +from tableauserverclient.models import Resource def main(): @@ -46,8 +46,8 @@ def main(): # get list of workbooks all_workbook_items, pagination_item = server.workbooks.get() if all_workbook_items is not None and len(all_workbook_items) > 0: - my_workbook: TSC.WorkbookItem = all_workbook_items[0] - server.favorites.add_favorite(server, user, Resource.Workbook.name(), all_workbook_items[0]) + my_workbook = all_workbook_items[0] + server.favorites.add_favorite(user, Resource.Workbook, all_workbook_items[0]) print( "Workbook added to favorites. Workbook Name: {}, Workbook ID: {}".format( my_workbook.name, my_workbook.id diff --git a/samples/list.py b/samples/list.py index 8d72fb620..c89120284 100644 --- a/samples/list.py +++ b/samples/list.py @@ -48,6 +48,9 @@ def main(): "webhooks": server.webhooks, "workbook": server.workbooks, }.get(args.resource_type) + if endpoint is None: + print("Resource type not found.") + sys.exit(1) options = TSC.RequestOptions() options.sort.add(TSC.Sort(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Direction.Desc)) diff --git a/tableauserverclient/models/favorites_item.py b/tableauserverclient/models/favorites_item.py index caff755e3..c9c5946d7 100644 --- a/tableauserverclient/models/favorites_item.py +++ b/tableauserverclient/models/favorites_item.py @@ -22,7 +22,7 @@ class FavoriteItem: @classmethod - def from_response(cls, xml: str, namespace: Dict) -> FavoriteType: + def from_response(cls, xml: Union[str, bytes], namespace: Dict) -> FavoriteType: favorites: FavoriteType = { "datasources": [], "flows": [], From a59f88e44134198bbe294828e12ccd148bc52dd4 Mon Sep 17 00:00:00 2001 From: Jac Date: Thu, 19 Sep 2024 00:23:57 -0700 Subject: [PATCH 2/4] Update favorites_item.py import Union --- tableauserverclient/models/favorites_item.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tableauserverclient/models/favorites_item.py b/tableauserverclient/models/favorites_item.py index 645c0f775..5e13a28b8 100644 --- a/tableauserverclient/models/favorites_item.py +++ b/tableauserverclient/models/favorites_item.py @@ -1,8 +1,9 @@ import logging +from typing import Union from defusedxml.ElementTree import fromstring -from tableauserverclient.models.tableau_types import TableauItem +from tableauserverclient.models.tableau_types import TableauItem from tableauserverclient.models.datasource_item import DatasourceItem from tableauserverclient.models.flow_item import FlowItem from tableauserverclient.models.project_item import ProjectItem From 4339c82b51d1726affe3d63d470bc2799b7e3b86 Mon Sep 17 00:00:00 2001 From: Jac Date: Thu, 19 Sep 2024 00:27:36 -0700 Subject: [PATCH 3/4] Update favorites_item.py Dict -> dict --- tableauserverclient/models/favorites_item.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tableauserverclient/models/favorites_item.py b/tableauserverclient/models/favorites_item.py index 5e13a28b8..0cab3e2ae 100644 --- a/tableauserverclient/models/favorites_item.py +++ b/tableauserverclient/models/favorites_item.py @@ -1,6 +1,6 @@ import logging -from typing import Union +from typing import dict, Union from defusedxml.ElementTree import fromstring from tableauserverclient.models.tableau_types import TableauItem @@ -21,7 +21,7 @@ class FavoriteItem: @classmethod - def from_response(cls, xml: Union[str, bytes], namespace: Dict) -> FavoriteType: + def from_response(cls, xml: Union[str, bytes], namespace: dict) -> FavoriteType: favorites: FavoriteType = { "datasources": [], "flows": [], From 1ee12fa1bff3903d21c2fcfa8bf3139e581a8c49 Mon Sep 17 00:00:00 2001 From: Jordan Woods <13803242+jorwoods@users.noreply.github.com> Date: Thu, 19 Sep 2024 03:52:03 -0500 Subject: [PATCH 4/4] fix: dict import --- tableauserverclient/models/favorites_item.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tableauserverclient/models/favorites_item.py b/tableauserverclient/models/favorites_item.py index 0cab3e2ae..4fea280f7 100644 --- a/tableauserverclient/models/favorites_item.py +++ b/tableauserverclient/models/favorites_item.py @@ -1,6 +1,6 @@ import logging -from typing import dict, Union +from typing import Union from defusedxml.ElementTree import fromstring from tableauserverclient.models.tableau_types import TableauItem