Skip to content

Commit 863ec9c

Browse files
Fix some type hints
1 parent 03312b3 commit 863ec9c

File tree

12 files changed

+75
-69
lines changed

12 files changed

+75
-69
lines changed

databricks/sdk/__init__.py

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

databricks/sdk/_base_client.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@ class _BaseClient:
4343

4444
def __init__(
4545
self,
46-
debug_truncate_bytes: int = None,
47-
retry_timeout_seconds: int = None,
48-
user_agent_base: str = None,
49-
header_factory: Callable[[], dict] = None,
50-
max_connection_pools: int = None,
51-
max_connections_per_pool: int = None,
52-
pool_block: bool = True,
53-
http_timeout_seconds: float = None,
54-
extra_error_customizers: List[_ErrorCustomizer] = None,
55-
debug_headers: bool = False,
56-
clock: Clock = None,
46+
debug_truncate_bytes: Optional[int] = None,
47+
retry_timeout_seconds: Optional[int] = None,
48+
user_agent_base: Optional[str] = None,
49+
header_factory: Optional[Callable[[], dict]] = None,
50+
max_connection_pools: Optional[int] = None,
51+
max_connections_per_pool: Optional[int] = None,
52+
pool_block: Optional[bool] = True,
53+
http_timeout_seconds: Optional[float] = None,
54+
extra_error_customizers: Optional[List[_ErrorCustomizer]] = None,
55+
debug_headers: Optional[bool] = False,
56+
clock: Optional[Clock] = None,
5757
streaming_buffer_size: int = 1024 * 1024,
5858
): # 1MB
5959
"""
@@ -148,14 +148,14 @@ def do(
148148
self,
149149
method: str,
150150
url: str,
151-
query: dict = None,
152-
headers: dict = None,
153-
body: dict = None,
151+
query: Optional[dict] = None,
152+
headers: Optional[dict] = None,
153+
body: Optional[dict] = None,
154154
raw: bool = False,
155155
files=None,
156156
data=None,
157-
auth: Callable[[requests.PreparedRequest], requests.PreparedRequest] = None,
158-
response_headers: List[str] = None,
157+
auth: Optional[Callable[[requests.PreparedRequest], requests.PreparedRequest]] = None,
158+
response_headers: Optional[List[str]] = None,
159159
) -> Union[dict, list, BinaryIO]:
160160
if headers is None:
161161
headers = {}
@@ -272,9 +272,9 @@ def _perform(
272272
self,
273273
method: str,
274274
url: str,
275-
query: dict = None,
276-
headers: dict = None,
277-
body: dict = None,
275+
query: Optional[dict] = None,
276+
headers: Optional[dict] = None,
277+
body: Optional[dict] = None,
278278
raw: bool = False,
279279
files=None,
280280
data=None,
@@ -325,10 +325,10 @@ class _StreamingResponse(BinaryIO):
325325
_closed: bool = False
326326

327327
def fileno(self) -> int:
328-
pass
328+
return 0
329329

330-
def flush(self) -> int:
331-
pass
330+
def flush(self) -> int: # type: ignore
331+
return 0
332332

333333
def __init__(self, response: _RawResponse, chunk_size: Union[int, None] = None):
334334
self._response = response
@@ -403,10 +403,10 @@ def truncate(self, __size: Union[int, None] = ...) -> int:
403403
def writable(self) -> bool:
404404
return False
405405

406-
def write(self, s: Union[bytes, bytearray]) -> int:
406+
def write(self, s: Union[bytes, bytearray]) -> int: # type: ignore
407407
raise NotImplementedError()
408408

409-
def writelines(self, lines: Iterable[bytes]) -> None:
409+
def writelines(self, lines: Iterable[bytes]) -> None: # type: ignore
410410
raise NotImplementedError()
411411

412412
def __next__(self) -> bytes:

databricks/sdk/_widgets/ipywidgets_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def value(self):
3030
if type(value) == list or type(value) == tuple:
3131
return ",".join(value)
3232

33-
raise ValueError("The returned value has invalid type (" + type(value) + ").")
33+
raise ValueError(f"The returned value has invalid type ({type(value)}).")
3434

3535

3636
class IPyWidgetUtil(WidgetUtils):

databricks/sdk/core.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ def get_oauth_token(self, auth_details: str) -> Token:
6666
def do(
6767
self,
6868
method: str,
69-
path: str = None,
70-
url: str = None,
71-
query: dict = None,
72-
headers: dict = None,
73-
body: dict = None,
69+
path: Optional[str] = None,
70+
url: Optional[str] = None,
71+
query: Optional[dict] = None,
72+
headers: Optional[dict] = None,
73+
body: Optional[dict] = None,
7474
raw: bool = False,
7575
files=None,
7676
data=None,
77-
auth: Callable[[requests.PreparedRequest], requests.PreparedRequest] = None,
78-
response_headers: List[str] = None,
77+
auth: Optional[Callable[[requests.PreparedRequest], requests.PreparedRequest]] = None,
78+
response_headers: Optional[List[str]] = None,
7979
) -> Union[dict, list, BinaryIO]:
8080
if url is None:
8181
# Remove extra `/` from path for Files API

databricks/sdk/environments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def azure_active_directory_endpoint(self) -> Optional[str]:
113113
]
114114

115115

116-
def get_environment_for_hostname(hostname: str) -> DatabricksEnvironment:
116+
def get_environment_for_hostname(hostname: Optional[str]) -> DatabricksEnvironment:
117117
if not hostname:
118118
return DEFAULT_ENVIRONMENT
119119
for env in ALL_ENVS:

databricks/sdk/errors/base.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22
import warnings
33
from dataclasses import dataclass
4-
from typing import Dict, List, Optional
4+
from typing import Any, Dict, List, Optional
55

66
import requests
77

@@ -12,10 +12,10 @@
1212
class ErrorDetail:
1313
def __init__(
1414
self,
15-
type: str = None,
16-
reason: str = None,
17-
domain: str = None,
18-
metadata: dict = None,
15+
type: Optional[str] = None,
16+
reason: Optional[str] = None,
17+
domain: Optional[str] = None,
18+
metadata: Optional[dict] = None,
1919
**kwargs,
2020
):
2121
self.type = type
@@ -24,7 +24,7 @@ def __init__(
2424
self.metadata = metadata
2525

2626
@classmethod
27-
def from_dict(cls, d: Dict[str, any]) -> "ErrorDetail":
27+
def from_dict(cls, d: Dict[str, Any]) -> "ErrorDetail":
2828
# Key "@type" is not a valid keyword argument name in Python. Rename
2929
# it to "type" to avoid conflicts.
3030
safe_args = {}
@@ -39,15 +39,15 @@ class DatabricksError(IOError):
3939

4040
def __init__(
4141
self,
42-
message: str = None,
42+
message: Optional[str] = None,
4343
*,
44-
error_code: str = None,
45-
detail: str = None,
46-
status: str = None,
47-
scimType: str = None,
48-
error: str = None,
49-
retry_after_secs: int = None,
50-
details: List[Dict[str, any]] = None,
44+
error_code: Optional[str] = None,
45+
detail: Optional[str] = None,
46+
status: Optional[str] = None,
47+
scimType: Optional[str] = None,
48+
error: Optional[str] = None,
49+
retry_after_secs: Optional[int] = None,
50+
details: Optional[List[Dict[str, Any]]] = None,
5151
**kwargs,
5252
):
5353
"""
@@ -102,7 +102,7 @@ def __init__(
102102
super().__init__(message if message else error)
103103
self.error_code = error_code
104104
self.retry_after_secs = retry_after_secs
105-
self._error_details = errdetails.parse_error_details(details)
105+
self._error_details = errdetails.parse_error_details(details or [])
106106
self.kwargs = kwargs
107107

108108
# Deprecated.

databricks/sdk/logger/round_trip_logger.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
22
import urllib.parse
3-
from typing import Dict, List
3+
from typing import Any, Dict, List
44

55
import requests
66

@@ -99,7 +99,7 @@ def _recursive_marshal_list(self, s, budget) -> list:
9999
budget -= len(str(raw))
100100
return out
101101

102-
def _recursive_marshal(self, v: any, budget: int) -> any:
102+
def _recursive_marshal(self, v: Any, budget: int) -> Any:
103103
if isinstance(v, dict):
104104
return self._recursive_marshal_dict(v, budget)
105105
elif isinstance(v, list):

databricks/sdk/mixins/workspace.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
from typing import BinaryIO, Iterator, Optional, Union
1+
from typing import Any, BinaryIO, Iterator, Optional, Union
22

33
from ..core import DatabricksError
44
from ..service.workspace import (ExportFormat, ImportFormat, Language,
55
ObjectInfo, ObjectType, WorkspaceAPI)
66

77

8-
def _fqcn(x: any) -> str:
8+
def _fqcn(x: Any) -> str:
99
return f"{x.__module__}.{x.__name__}"
1010

1111

databricks/sdk/oauth.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ def as_dict(self) -> dict:
7878
@dataclass
7979
class Token:
8080
access_token: str
81-
token_type: str = None
82-
refresh_token: str = None
83-
expiry: datetime = None
81+
token_type: Optional[str] = None
82+
refresh_token: Optional[str] = None
83+
expiry: Optional[datetime] = None
8484

8585
@property
8686
def expired(self):
@@ -238,7 +238,7 @@ def _get_executor(cls):
238238

239239
def __init__(
240240
self,
241-
token: Token = None,
241+
token: Optional[Token] = None,
242242
disable_async: bool = True,
243243
stale_duration: timedelta = _DEFAULT_STALE_DURATION,
244244
):
@@ -248,7 +248,7 @@ def __init__(
248248
# Lock
249249
self._lock = threading.Lock()
250250
# Non Thread safe properties. They should be accessed only when protected by the lock above.
251-
self._token = token
251+
self._token = token or Token("")
252252
self._is_refreshing = False
253253
self._refresh_err = False
254254

@@ -312,7 +312,7 @@ def _trigger_async_refresh(self):
312312
"""Starts an asynchronous refresh if none is in progress."""
313313

314314
def _refresh_internal():
315-
new_token: Token = None
315+
new_token = None
316316
try:
317317
new_token = self.refresh()
318318
except Exception as e:
@@ -737,9 +737,9 @@ def __init__(
737737
host: str,
738738
oidc_endpoints: OidcEndpoints,
739739
client_id: str,
740-
redirect_url: str = None,
741-
client_secret: str = None,
742-
scopes: List[str] = None,
740+
redirect_url: Optional[str] = None,
741+
client_secret: Optional[str] = None,
742+
scopes: Optional[List[str]] = None,
743743
) -> None:
744744
self._host = host
745745
self._client_id = client_id

databricks/sdk/retries.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
def retried(
1313
*,
14-
on: Sequence[Type[BaseException]] = None,
15-
is_retryable: Callable[[BaseException], Optional[str]] = None,
14+
on: Optional[Sequence[Type[BaseException]]] = None,
15+
is_retryable: Optional[Callable[[BaseException], Optional[str]]] = None,
1616
timeout=timedelta(minutes=20),
17-
clock: Clock = None,
18-
before_retry: Callable = None,
17+
clock: Optional[Clock] = None,
18+
before_retry: Optional[Callable] = None,
1919
):
2020
has_allowlist = on is not None
2121
has_callback = is_retryable is not None

0 commit comments

Comments
 (0)