8000 mypy no-implicit-optional (#1151) · tableau/server-client-python@0bb9dd5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0bb9dd5

Browse files
authored
mypy no-implicit-optional (#1151)
1 parent 173c22a commit 0bb9dd5

12 files changed

+30
-29
lines changed

tableauserverclient/models/datasource_item.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class AskDataEnablement:
3434
Disabled = "Disabled"
3535
SiteDefault = "SiteDefault"
3636

37-
def __init__(self, project_id: str, name: str = None) -> None:
37+
def __init__(self, project_id: str, name: Optional[str] = None) -> None:
3838
self._ask_data_enablement = None
3939
self._certified = None
4040
self._certification_note = None

tableauserverclient/models/site_item.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ def __init__(
5050
self,
5151
name: str,
5252
content_url: str,
53-
admin_mode: str = None,
54-
user_quota: int = None,
55-
storage_quota: int = None,
53+
admin_mode: Optional[str] = None,
54+
user_quota: Optional[int] = None,
55+
storage_quota: Optional[int] = None,
5656
disable_subscriptions: bool = False,
5757
subscribe_others_enabled: bool = True,
5858
revision_history_enabled: bool = False,

tableauserverclient/models/workbook_item.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434

3535
class WorkbookItem(object):
36-
def __init__(self, project_id: str, name: str = None, show_tabs: bool = False) -> None:
36+
def __init__(self, project_id: str, name: Optional[str] = None, show_tabs: bool = False) -> None:
3737
self._connections = None
3838
self._content_url = None
3939
self._webpage_url = None

tableauserverclient/server/endpoint/datasources_endpoint.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def baseurl(self) -> str:
8080

8181
# Get all datasources
8282
@api(version="2.0")
83-
def get(self, req_options: RequestOptions = None) -> Tuple[List[DatasourceItem], PaginationItem]:
83+
def get(self, req_options: Optional[RequestOptions] = None) -> Tuple[List[DatasourceItem], PaginationItem]:
8484
logger.info("Querying all datasources on site")
8585
url = self.baseurl
8686
server_response = self.get_request(url, req_options)
@@ -135,7 +135,7 @@ def delete(self, datasource_id: str) -> None:
135135
def download(
136136
self,
137137
datasource_id: str,
138-
filepath: FilePath = None,
138+
filepath: Optional[FilePath] = None,
139139
include_extract: bool = True,
140140
no_extract: Optional[bool] = None,
141141
) -> str:
@@ -234,8 +234,8 @@ def publish(
234234
datasource_item: DatasourceItem,
235235
file: PathOrFile,
236236
mode: str,
237-
connection_credentials: ConnectionCredentials = None,
238-
connections: Sequence[ConnectionItem] = None,
237+
connection_credentials: Optional[ConnectionCredentials] = None,
238+
connections: Optional[Sequence[ConnectionItem]] = None,
239239
as_job: bool = False,
240240
) -> Union[DatasourceItem, JobItem]:
241241

tableauserverclient/server/endpoint/endpoint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def _make_request(
7878

7979
return server_response
8080

81-
def _check_status(self, server_response, url: str = None):
81+
def _check_status(self, server_response, url: Optional[str] = None):
8282
if server_response.status_code >= 500:
8383
raise InternalServerError(server_response, url)
8484
elif server_response.status_code not in Success_codes:

tableauserverclient/server/endpoint/exceptions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from defusedxml.ElementTree import fromstring
2+
from typing import Optional
23

34

45
class TableauError(Exception):
@@ -33,7 +34,7 @@ def from_response(cls, resp, ns, url=None):
3334

3435

3536
class InternalServerError(TableauError):
36-
def __init__(self, server_response, request_url: str = None):
37+
def __init__(self, server_response, request_url: Optional[str] = None):
3738
self.code = server_response.status_code
3839
self.content = server_response.content
3940
self.url = request_url or "server"

tableauserverclient/server/endpoint/flows_endpoint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def delete(self, flow_id: str) -> None:
9494

9595
# Download 1 flow by id
9696
@api(version="3.3")
97-
def download(self, flow_id: str, filepath: FilePath = None) -> str:
97+
def download(self, flow_id: str, filepath: Optional[FilePath] = None) -> str:
9898
if not flow_id:
9999
error = "Flow ID undefined."
100100
raise ValueError(error)

tableauserverclient/server/endpoint/permissions_endpoint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from .exceptions import MissingRequiredFieldError
77

88
from ...models import TableauItem
9-
from typing import Callable, TYPE_CHECKING, List, Union
9+
from typing import Optional, Callable, TYPE_CHECKING, List, Union
1010

1111
logger = logging.getLogger(__name__)
1212

@@ -82,7 +82,7 @@ def permission_fetcher():
8282
item._set_permissions(permission_fetcher)
8383
logger.info("Populated permissions for item (ID: {0})".format(item.id))
8484

85-
def _get_permissions(self, item: TableauItem, req_options: "RequestOptions" = None):
85+
def _get_permissions(self, item: TableauItem, req_options: Optional["RequestOptions"] = None):
8686
url = "{0}/{1}/permissions".format(self.owner_baseurl(), item.id)
8787
server_response = self.get_request(url, req_options)
8888
permissions = PermissionsRule.from_response(server_response.content, self.parent_srv.namespace)

tableauserverclient/server/endpoint/schedules_endpoint.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ def create(self, schedule_item: ScheduleItem) -> ScheduleItem:
8585
def add_to_schedule(
8686
self,
8787
schedule_id: str,
88-
workbook: "WorkbookItem" = None,
89-
datasource: "DatasourceItem" = None,
90-
flow: "FlowItem" = None,
91-
task_type: str = None,
88+
workbook: Optional["WorkbookItem"] = None,
89+
datasource: Optional["DatasourceItem"] = None,
90+
flow: Optional["FlowItem"] = None,
91+
task_type: Optional[str] = None,
9292
) -> List[AddResponse]:
9393

9494
# There doesn't seem to be a good reason to allow one item of each type?

tableauserverclient/server/endpoint/users_endpoint.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def baseurl(self) -> str:
2121

2222
# Gets all users
2323
@api(version="2.0")
24-
def get(self, req_options: RequestOptions = None) -> Tuple[List[UserItem], PaginationItem]:
24+
def get(self, req_options: Optional[RequestOptions] = None) -> Tuple[List[UserItem], PaginationItem]:
2525
logger.info("Querying all users on site")
2626

2727
if req_options is None:
@@ -47,7 +47,7 @@ def get_by_id(self, user_id: str) -> UserItem:
4747

4848
# Update user
4949
@api(version="2.0")
50-
def update(self, user_item: UserItem, password: str = None) -> UserItem:
50+
def update(self, user_item: UserItem, password: Optional[str] = None) -> UserItem:
5151
if not user_item.id:
5252
error = "User item missing ID."
5353
raise MissingRequiredFieldError(error)
@@ -122,7 +122,7 @@ def create_from_file(self, filepath: str) -> Tuple[List[UserItem], List[Tuple[Us
122122

123123
# Get workbooks for user
124124
@api(version="2.0")
125-
def populate_workbooks(self, user_item: UserItem, req_options: RequestOptions = None) -> None:
125+
def populate_workbooks(self, user_item: UserItem, req_options: Optional[RequestOptions] = None) -> None:
126126
if not user_item.id:
127127
error = "User item missing ID."
128128
raise MissingRequiredFieldError(error)
@@ -133,7 +133,7 @@ def wb_pager():
133133
user_item._set_workbooks(wb_pager)
134134

135135
def _get_wbs_for_user(
136-
self, user_item: UserItem, req_options: RequestOptions = None
136+
self, user_item: UserItem, req_options: Optional[RequestOptions] = None
137137
) -> Tuple[List[WorkbookItem], PaginationItem]:
138138
url = "{0}/{1}/workbooks".format(self.baseurl, user_item.id)
139139
server_response = self.get_request(url, req_options)
@@ -147,7 +147,7 @@ def populate_favorites(self, user_item: UserItem) -> None:
147147

148148
# Get groups for user
149149
@api(version="3.7")
150-
def populate_groups(self, user_item: UserItem, req_options: RequestOptions = None) -> None:
150+
def populate_groups(self, user_item: UserItem, req_options: Optional[RequestOptions] = None) -> None:
151151
if not user_item.id:
152152
error = "User item missing ID."
153153
raise MissingRequiredFieldError(error)
@@ -161,7 +161,7 @@ def groups_for_user_pager():
161161
user_item._set_groups(groups_for_user_pager)
162162

163163
def _get_groups_for_user(
164-
self, user_item: UserItem, req_options: RequestOptions = None
164+
self, user_item: UserItem, req_options: Optional[RequestOptions] = None
165165
) -> Tuple[List[GroupItem], PaginationItem]:
166166
url = "{0}/{1}/groups".format(self.baseurl, user_item.id)
167167
server_response = self.get_request(url, req_options)

tableauserverclient/server/endpoint/workbooks_endpoint.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def update_connection(self, workbook_item: WorkbookItem, connection_item: Connec
178178
def download(
179179
self,
180180
workbook_id: str,
181-
filepath: FilePath = None,
181+
filepath: Optional[FilePath] = None,
182182
include_extract: bool = True,
183183
no_extract: Optional[bool] = None,
184184
) -> str:
@@ -250,7 +250,7 @@ def connection_fetcher():
250250
logger.info("Populated connections for workbook (ID: {0})".format(workbook_item.id))
251251

252252
def _get_workbook_connections(
253-
self, workbook_item: WorkbookItem, req_options: "RequestOptions" = None
253+
self, workbook_item: WorkbookItem, req_options: Optional["RequestOptions"] = None
254254
) -> List[ConnectionItem]:
255255
url = "{0}/{1}/connections".format(self.baseurl, workbook_item.id)
256256
server_response = self.get_request(url, req_options)
@@ -259,7 +259,7 @@ def _get_workbook_connections(
259259

260260
# Get the pdf of the entire workbook if its tabs are enabled, pdf of the default view if its tabs are disabled
261261
@api(version="3.4")
262-
def populate_pdf(self, workbook_item: WorkbookItem, req_options: "RequestOptions" = None) -> None:
262+
def populate_pdf(self, workbook_item: WorkbookItem, req_options: Optional["RequestOptions"] = None) -> None:
263263
if not workbook_item.id:
264264
error = "Workbook item missing ID."
265265
raise MissingRequiredFieldError(error)

tableauserverclient/server/request_factory.py

Lines changed: 2 additions & 2 deletions
Diff line number
Original file line numberDiff line change
@@ -575,7 +575,7 @@ def add_flow_req(self, id_: Optional[str], task_type: str = TaskItem.Type.RunFlo
575575

576576

577577
class SiteRequest(object):
578-
def update_req(self, site_item: "SiteItem", parent_srv: "Server" = None):
578+
def update_req(self, site_item: "SiteItem", parent_srv: Optional["Server"] = None):
579579
xml_request = ET.Element("tsRequest")
580580
site_element = ET.SubElement(xml_request, "site")
581581
if site_item.name:
@@ -683,7 +683,7 @@ def update_req(self, site_item: "SiteItem", parent_srv: "Server" = None):
683683
return ET.tostring(xml_request)
684684

685685
# server: the site request model changes based on api version
686-
def create_req(self, site_item: "SiteItem", parent_srv: "Server" = None):
686+
def create_req(self, site_item: "SiteItem", parent_srv: Optional["Server"] = None):
687687
xml_request = ET.Element("tsRequest")
688688
site_element = ET.SubElement(xml_request, "site")
689689
site_element.attrib["name"] = site_item.name

0 commit comments

Comments
 (0)
0