Skip to content

Commit a5cfd13

Browse files
committed
chore: modernize Optional type hints
1 parent d61efde commit a5cfd13

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+911
-944
lines changed

tableauserverclient/bin/_version.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
import re
1717
import subprocess
1818
import sys
19-
from typing import Any, Callable, Dict, List, Optional, Tuple
19+
from typing import Any, Callable
2020
import functools
2121

2222

23-
def get_keywords() -> Dict[str, str]:
23+
def get_keywords() -> dict[str, str]:
2424
"""Get the keywords needed to look up the version information."""
2525
# these strings will be replaced by git during git-archive.
2626
# setup.py/versioneer.py will grep for the variable names, so they must
@@ -61,8 +61,8 @@ class NotThisMethod(Exception):
6161
"""Exception raised if a method is not valid for the current scenario."""
6262

6363

64-
LONG_VERSION_PY: Dict[str, str] = {}
65-
HANDLERS: Dict[str, Dict[str, Callable]] = {}
64+
LONG_VERSION_PY: dict[str, str] = {}
65+
HANDLERS: dict[str, dict[str, Callable]] = {}
6666

6767

6868
def register_vcs_handler(vcs: str, method: str) -> Callable: # decorator
@@ -77,18 +77,18 @@ def decorate(f: Callable) -> Callable:
7777

7878

7979
def run_command(
80-
commands: List[str],
81-
args: List[str],
82-
cwd: Optional[str] = None,
80+
commands: list[str],
81+
args: list[str],
82+
cwd: str | None = None,
8383
verbose: bool = False,
8484
hide_stderr: bool = False,
85-
env: Optional[Dict[str, str]] = None,
86-
) -> Tuple[Optional[str], Optional[int]]:
85+
env: dict[str, str] | None = None,
86+
) -> tuple[str | None, int | None]:
8787
"""Call the given command(s)."""
8888
assert isinstance(commands, list)
8989
process = None
9090

91-
popen_kwargs: Dict[str, Any] = {}
91+
popen_kwargs: dict[str, Any] = {}
9292
if sys.platform == "win32":
9393
# This hides the console window if pythonw.exe is used
9494
startupinfo = subprocess.STARTUPINFO()
@@ -128,7 +128,7 @@ def versions_from_parentdir(
128128
parentdir_prefix: str,
129129
root: str,
130130
verbose: bool,
131-
) -> Dict[str, Any]:
131+
) -> dict[str, Any]:
132132
"""Try to determine the version from the parent directory name.
133133
134134
Source tarballs conventionally unpack into a directory that includes both
@@ -153,13 +153,13 @@ def versions_from_parentdir(
153153

154154

155155
@register_vcs_handler("git", "get_keywords")
156-
def git_get_keywords(versionfile_abs: str) -> Dict[str, str]:
156+
def git_get_keywords(versionfile_abs: str) -> dict[str, str]:
157157
"""Extract version information from the given file."""
158158
# the code embedded in _version.py can just fetch the value of these
159159
# keywords. When used from setup.py, we don't want to import _version.py,
160160
# so we do it with a regexp instead. This function is not used from
161161
# _version.py.
162-
keywords: Dict[str, str] = {}
162+
keywords: dict[str, str] = {}
163163
try:
164164
with open(versionfile_abs, "r") as fobj:
165165
for line in fobj:
@@ -182,10 +182,10 @@ def git_get_keywords(versionfile_abs: str) -> Dict[str, str]:
182182

183183
@register_vcs_handler("git", "keywords")
184184
def git_versions_from_keywords(
185-
keywords: Dict[str, str],
185+
keywords: dict[str, str],
186186
tag_prefix: str,
187187
verbose: bool,
188-
) -> Dict[str, Any]:
188+
) -> dict[str, Any]:
189189
"""Get version information from git keywords."""
190190
if "refnames" not in keywords:
191191
raise NotThisMethod("Short version file found")
@@ -254,7 +254,7 @@ def git_pieces_from_vcs(
254254
root: str,
255255
verbose: bool,
256256
runner: Callable = run_command
257-
) -> Dict[str, Any]:
257+
) -> dict[str, Any]:
258258
"""Get version from 'git describe' in the root of the source tree.
259259
260260
This only gets called if the git-archive 'subst' keywords were *not*
@@ -294,7 +294,7 @@ def git_pieces_from_vcs(
294294
raise NotThisMethod("'git rev-parse' failed")
295295
full_out = full_out.strip()
296296

297-
pieces: Dict[str, Any] = {}
297+
pieces: dict[str, Any] = {}
298298
pieces["long"] = full_out
299299
pieces["short"] = full_out[:7] # maybe improved later
300300
pieces["error"] = None
@@ -386,14 +386,14 @@ def git_pieces_from_vcs(
386386
return pieces
387387

388388

389-
def plus_or_dot(pieces: Dict[str, Any]) -> str:
389+
def plus_or_dot(pieces: dict[str, Any]) -> str:
390390
"""Return a + if we don't already have one, else return a ."""
391391
if "+" in pieces.get("closest-tag", ""):
392392
return "."
393393
return "+"
394394

395395

396-
def render_pep440(pieces: Dict[str, Any]) -> str:
396+
def render_pep440(pieces: dict[str, Any]) -> str:
397397
"""Build up version string, with post-release "local version identifier".
398398
399399
Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you
@@ -418,7 +418,7 @@ def render_pep440(pieces: Dict[str, Any]) -> str:
418418
return rendered
419419

420420

421-
def render_pep440_branch(pieces: Dict[str, Any]) -> str:
421+
def render_pep440_branch(pieces: dict[str, Any]) -> str:
422422
"""TAG[[.dev0]+DISTANCE.gHEX[.dirty]] .
423423
424424
The ".dev0" means not master branch. Note that .dev0 sorts backwards
@@ -448,7 +448,7 @@ def render_pep440_branch(pieces: Dict[str, Any]) -> str:
448448
return rendered
449449

450450

451-
def pep440_split_post(ver: str) -> Tuple[str, Optional[int]]:
451+
def pep440_split_post(ver: str) -> tuple[str, int | None]:
452452
"""Split pep440 version string at the post-release segment.
453453
454454
Returns the release segments before the post-release and the
@@ -458,7 +458,7 @@ def pep440_split_post(ver: str) -> Tuple[str, Optional[int]]:
458458
return vc[0], int(vc[1] or 0) if len(vc) == 2 else None
459459

460460

461-
def render_pep440_pre(pieces: Dict[str, Any]) -> str:
461+
def render_pep440_pre(pieces: dict[str, Any]) -> str:
462462
"""TAG[.postN.devDISTANCE] -- No -dirty.
463463
464464
Exceptions:
@@ -482,7 +482,7 @@ def render_pep440_pre(pieces: Dict[str, Any]) -> str:
482482
return rendered
483483

484484

485-
def render_pep440_post(pieces: Dict[str, Any]) -> str:
485+
def render_pep440_post(pieces: dict[str, Any]) -> str:
486486
"""TAG[.postDISTANCE[.dev0]+gHEX] .
487487
488488
The ".dev0" means dirty. Note that .dev0 sorts backwards
@@ -509,7 +509,7 @@ def render_pep440_post(pieces: Dict[str, Any]) -> str:
509509
return rendered
510510

511511

512-
def render_pep440_post_branch(pieces: Dict[str, Any]) -> str:
512+
def render_pep440_post_branch(pieces: dict[str, Any]) -> str:
513513
"""TAG[.postDISTANCE[.dev0]+gHEX[.dirty]] .
514514
515515
The ".dev0" means not master branch.
@@ -538,7 +538,7 @@ def render_pep440_post_branch(pieces: Dict[str, Any]) -> str:
538538
return rendered
539539

540540

541-
def render_pep440_old(pieces: Dict[str, Any]) -> str:
541+
def render_pep440_old(pieces: dict[str, Any]) -> str:
542542
"""TAG[.postDISTANCE[.dev0]] .
543543
544544
The ".dev0" means dirty.
@@ -560,7 +560,7 @@ def render_pep440_old(pieces: Dict[str, Any]) -> str:
560560
return rendered
561561

562562

563-
def render_git_describe(pieces: Dict[str, Any]) -> str:
563+
def render_git_describe(pieces: dict[str, Any]) -> str:
564564
"""TAG[-DISTANCE-gHEX][-dirty].
565565
566566
Like 'git describe --tags --dirty --always'.
@@ -580,7 +580,7 @@ def render_git_describe(pieces: Dict[str, Any]) -> str:
580580
return rendered
581581

582582

583-
def render_git_describe_long(pieces: Dict[str, Any]) -> str:
583+
def render_git_describe_long(pieces: dict[str, Any]) -> str:
584584
"""TAG-DISTANCE-gHEX[-dirty].
585585
586586
Like 'git describe --tags --dirty --always -long'.
@@ -600,7 +600,7 @@ def render_git_describe_long(pieces: Dict[str, Any]) -> str:
600600
return rendered
601601

602602

603-
def render(pieces: Dict[str, Any], style: str) -> Dict[str, Any]:
603+
def render(pieces: dict[str, Any], style: str) -> dict[str, Any]:
604604
"""Render the given version pieces into the requested style."""
605605
if pieces["error"]:
606606
return {"version": "unknown",
@@ -636,7 +636,7 @@ def render(pieces: Dict[str, Any], style: str) -> Dict[str, Any]:
636636
"date": pieces.get("date")}
637637

638638

639-
def get_versions() -> Dict[str, Any]:
639+
def get_versions() -> dict[str, Any]:
640640
"""Get version information or return default if unable to do so."""
641641
# I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have
642642
# __file__, we can work backwards from there to the root. Some

tableauserverclient/models/collection_item.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from datetime import datetime
2-
from typing import Optional
32
from xml.etree.ElementTree import Element
43

54
from defusedxml.ElementTree import fromstring
@@ -11,15 +10,15 @@
1110

1211
class CollectionItem:
1312
def __init__(self) -> None:
14-
self.id: Optional[str] = None
15-
self.name: Optional[str] = None
16-
self.description: Optional[str] = None
17-
self.created_at: Optional[datetime] = None
18-
self.updated_at: Optional[datetime] = None
19-
self.owner: Optional[UserItem] = None
20-
self.total_item_count: Optional[int] = None
21-
self.permissioned_item_count: Optional[int] = None
22-
self.visibility: Optional[str] = None # Assuming visibility is a string, adjust as necessary
13+
self.id: str | None = None
14+
self.name: str | None = None
15+
self.description: str | None = None
16+
self.created_at: datetime | None = None
17+
self.updated_at: datetime | None = None
18+
self.owner: UserItem | None = None
19+
self.total_item_count: int | None = None
20+
self.permissioned_item_count: int | None = None
21+
self.visibility: str | None = None # Assuming visibility is a string, adjust as necessary
2322

2423
@classmethod
2524
def from_response(cls, response: bytes, ns) -> list[Self]:

tableauserverclient/models/connection_item.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
from typing import Optional
32

43
from defusedxml.ElementTree import fromstring
54

@@ -51,42 +50,42 @@ class ConnectionItem:
5150
"""
5251

5352
def __init__(self):
54-
self._datasource_id: Optional[str] = None
55-
self._datasource_name: Optional[str] = None
56-
self._id: Optional[str] = None
57-
self._connection_type: Optional[str] = None
53+
self._datasource_id: str | None = None
54+
self._datasource_name: str | None = None
55+
self._id: str | None = None
56+
self._connection_type: str | None = None
5857
self.embed_password: bool = None
59-
self.password: Optional[str] = None
60-
self.server_address: Optional[str] = None
61-
self.server_port: Optional[str] = None
62-
self.username: Optional[str] = None
63-
self.connection_credentials: Optional[ConnectionCredentials] = None
64-
self._query_tagging: Optional[bool] = None
65-
self._auth_type: Optional[str] = None
58+
self.password: str | None = None
59+
self.server_address: str | None = None
60+
self.server_port: str | None = None
61+
self.username: str | None = None
62+
self.connection_credentials: ConnectionCredentials | None = None
63+
self._query_tagging: bool | None = None
64+
self._auth_type: str | None = None
6665

6766
@property
68-
def datasource_id(self) -> Optional[str]:
67+
def datasource_id(self) -> str | None:
6968
return self._datasource_id
7069

7170
@property
72-
def datasource_name(self) -> Optional[str]:
71+
def datasource_name(self) -> str | None:
7372
return self._datasource_name
7473

7574
@property
76-
def id(self) -> Optional[str]:
75+
def id(self) -> str | None:
7776
return self._id
7877

7978
@property
80-
def connection_type(self) -> Optional[str]:
79+
def connection_type(self) -> str | None:
8180
return self._connection_type
8281

8382
@property
84-
def query_tagging(self) -> Optional[bool]:
83+
def query_tagging(self) -> bool | None:
8584
return self._query_tagging
8685

8786
@query_tagging.setter
8887
@property_is_boolean
89-
def query_tagging(self, value: Optional[bool]):
88+
def query_tagging(self, value: bool | None):
9089
# if connection type = hyper, Snowflake, or Teradata, we can't change this value: it is always true
9190
if self._connection_type in ["hyper", "snowflake", "teradata"]:
9291
logger.debug(
@@ -96,11 +95,11 @@ def query_tagging(self, value: Optional[bool]):
9695
self._query_tagging = value
9796

9897
@property
99-
def auth_type(self) -> Optional[str]:
98+
def auth_type(self) -> str | None:
10099
return self._auth_type
101100

102101
@auth_type.setter
103-
def auth_type(self, value: Optional[str]):
102+
def auth_type(self, value: str | None):
104103
self._auth_type = value
105104

106105
def __repr__(self):

0 commit comments

Comments
 (0)