Skip to content

Commit c3aad28

Browse files
authored
[Fix] Use correct optional typing in WorkspaceClient for mypy (#760)
Without this change, the SDK is not very `mypy`-compatible. This PR fixes `arg-type` check: ``` cmd [3] | mypy --disable-error-code 'annotation-unchecked' --exclude 'tests/resources/*' --exclude dist . error: Argument "auth_type" to "WorkspaceClient" has incompatible type "str | None"; expected "str" [arg-type] error: Argument "token" to "WorkspaceClient" has incompatible type "str | None"; expected "str" [arg-type] ``` `Optional[X]` is py3.8 and py3.9 way of expressing optional types, but in py3.10+ it gets transformed into a union type of `X | None`, which is not supported by py3.9. py3.9 EOL is 31 Oct 2025, so we have to deal with it somehow until then.
1 parent 3162545 commit c3aad28

File tree

3 files changed

+63
-61
lines changed

3 files changed

+63
-61
lines changed

.codegen/__init__.py.tmpl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ class WorkspaceClient:
4141
"""
4242
The WorkspaceClient is a client for the workspace-level Databricks REST API.
4343
"""
44-
def __init__(self, *{{range $args}}, {{.}}: str = None{{end}},
45-
debug_truncate_bytes: int = None,
46-
debug_headers: bool = None,
44+
def __init__(self, *{{range $args}}, {{.}}: Optional[str] = None{{end}},
45+
debug_truncate_bytes: Optional[int] = None,
46+
debug_headers: Optional[bool] = None,
4747
product="unknown",
4848
product_version="0.0.0",
49-
credentials_strategy: CredentialsStrategy = None,
50-
credentials_provider: CredentialsStrategy = None,
51-
config: client.Config = None):
49+
credentials_strategy: Optional[CredentialsStrategy] = None,
50+
credentials_provider: Optional[CredentialsStrategy] = None,
51+
config: Optional[client.Config] = None):
5252
if not config:
5353
config = client.Config({{range $args}}{{.}}={{.}}, {{end}}
5454
credentials_strategy=credentials_strategy,
@@ -110,14 +110,14 @@ class AccountClient:
110110
The AccountClient is a client for the account-level Databricks REST API.
111111
"""
112112

113-
def __init__(self, *{{range $args}}, {{.}}: str = None{{end}},
114-
debug_truncate_bytes: int = None,
115-
debug_headers: bool = None,
113+
def __init__(self, *{{range $args}}, {{.}}: Optional[str] = None{{end}},
114+
debug_truncate_bytes: Optional[int] = None,
115+
debug_headers: Optional[bool] = None,
116116
product="unknown",
117117
product_version="0.0.0",
118-
credentials_strategy: CredentialsStrategy = None,
119-
credentials_provider: CredentialsStrategy = None,
120-
config: client.Config = None):
118+
credentials_strategy: Optional[CredentialsStrategy] = None,
119+
credentials_provider: Optional[CredentialsStrategy] = None,
120+
config: Optional[client.Config] = None):
121121
if not config:
122122
config = client.Config({{range $args}}{{.}}={{.}}, {{end}}
123123
credentials_strategy=credentials_strategy,

databricks/sdk/__init__.py

Lines changed: 48 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

databricks/sdk/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ class Config:
9292
def __init__(self,
9393
*,
9494
# Deprecated. Use credentials_strategy instead.
95-
credentials_provider: CredentialsStrategy = None,
96-
credentials_strategy: CredentialsStrategy = None,
95+
credentials_provider: Optional[CredentialsStrategy] = None,
96+
credentials_strategy: Optional[CredentialsStrategy] = None,
9797
product=None,
9898
product_version=None,
99-
clock: Clock = None,
99+
clock: Optional[Clock] = None,
100100
**kwargs):
101101
self._header_factory = None
102102
self._inner = {}

0 commit comments

Comments
 (0)