Skip to content

Commit 352126d

Browse files
JCZuurmondnfx
andauthored
[TECH DEBT] Add type hints for cached properties (#2813)
## Changes Add type hints for cached properties and resolve the linting issues found after adding the type hints. Would have caught the integration test issues introduced in #2772 --------- Co-authored-by: Serge Smertin <[email protected]>
1 parent 6e25a39 commit 352126d

File tree

13 files changed

+154
-131
lines changed

13 files changed

+154
-131
lines changed

src/databricks/labs/ucx/account/aggregate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def __init__(
4949
self._workspace_context_factory = workspace_context_factory
5050

5151
@cached_property
52-
def _workspace_contexts(self):
52+
def _workspace_contexts(self) -> list[WorkspaceContext]:
5353
contexts = []
5454
for workspace_client in self._account_workspaces.workspace_clients():
5555
ctx = self._workspace_context_factory(workspace_client)

src/databricks/labs/ucx/cli.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,11 +593,19 @@ def assign_metastore(
593593
ctx: AccountContext | None = None,
594594
):
595595
"""Assign metastore to a workspace"""
596+
if workspace_id is None:
597+
logger.error("--workspace-id is a required parameter.")
598+
return
599+
try:
600+
workspace_id_casted = int(workspace_id)
601+
except ValueError:
602+
logger.error("--workspace-id should be an integer.")
603+
return
596604
logger.info(f"Account ID: {a.config.account_id}")
597605
ctx = ctx or AccountContext(a)
598606
ctx.account_metastores.assign_metastore(
599607
ctx.prompts,
600-
workspace_id,
608+
workspace_id_casted,
601609
metastore_id=metastore_id,
602610
default_catalog=default_catalog,
603611
)
@@ -635,7 +643,7 @@ def migrate_tables(
635643
deployed_workflows = workspace_context.deployed_workflows
636644
deployed_workflows.run_workflow("migrate-tables")
637645

638-
tables = workspace_context.tables_crawler.snapshot()
646+
tables = list(workspace_context.tables_crawler.snapshot())
639647
hiveserde_tables = [table for table in tables if table.what == What.EXTERNAL_HIVESERDE]
640648
if len(hiveserde_tables) > 0:
641649
percentage_hiveserde_tables = len(hiveserde_tables) / len(tables) * 100

src/databricks/labs/ucx/contexts/account_cli.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ def account_client(self) -> AccountClient:
1919
return self._ac
2020

2121
@cached_property
22-
def workspace_ids(self):
22+
def workspace_ids(self) -> list[int]:
2323
return [int(_.strip()) for _ in self.named_parameters.get("workspace_ids", "").split(",") if _]
2424

2525
@cached_property
26-
def account_workspaces(self):
26+
def account_workspaces(self) -> AccountWorkspaces:
2727
return AccountWorkspaces(self.account_client, self.workspace_ids)
2828

2929
@cached_property
30-
def account_aggregate(self):
30+
def account_aggregate(self) -> AccountAggregate:
3131
return AccountAggregate(self.account_workspaces)
3232

3333
@cached_property
34-
def is_account_install(self):
34+
def is_account_install(self) -> bool:
3535
return environ.get("UCX_FORCE_INSTALL") == "account"
3636

3737
@cached_property
38-
def account_metastores(self):
38+
def account_metastores(self) -> AccountMetastores:
3939
return AccountMetastores(self.account_client)

0 commit comments

Comments
 (0)