Skip to content

Commit

Permalink
[TECH DEBT] Add type hints for cached properties (#2813)
Browse files Browse the repository at this point in the history
## 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 <serge.smertin@databricks.com>
  • Loading branch information
JCZuurmond and nfx authored Oct 3, 2024
1 parent 6e25a39 commit 352126d
Show file tree
Hide file tree
Showing 13 changed files with 154 additions and 131 deletions.
2 changes: 1 addition & 1 deletion src/databricks/labs/ucx/account/aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(
self._workspace_context_factory = workspace_context_factory

@cached_property
def _workspace_contexts(self):
def _workspace_contexts(self) -> list[WorkspaceContext]:
contexts = []
for workspace_client in self._account_workspaces.workspace_clients():
ctx = self._workspace_context_factory(workspace_client)
Expand Down
12 changes: 10 additions & 2 deletions src/databricks/labs/ucx/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,11 +593,19 @@ def assign_metastore(
ctx: AccountContext | None = None,
):
"""Assign metastore to a workspace"""
if workspace_id is None:
logger.error("--workspace-id is a required parameter.")
return
try:
workspace_id_casted = int(workspace_id)
except ValueError:
logger.error("--workspace-id should be an integer.")
return
logger.info(f"Account ID: {a.config.account_id}")
ctx = ctx or AccountContext(a)
ctx.account_metastores.assign_metastore(
ctx.prompts,
workspace_id,
workspace_id_casted,
metastore_id=metastore_id,
default_catalog=default_catalog,
)
Expand Down Expand Up @@ -635,7 +643,7 @@ def migrate_tables(
deployed_workflows = workspace_context.deployed_workflows
deployed_workflows.run_workflow("migrate-tables")

tables = workspace_context.tables_crawler.snapshot()
tables = list(workspace_context.tables_crawler.snapshot())
hiveserde_tables = [table for table in tables if table.what == What.EXTERNAL_HIVESERDE]
if len(hiveserde_tables) > 0:
percentage_hiveserde_tables = len(hiveserde_tables) / len(tables) * 100
Expand Down
10 changes: 5 additions & 5 deletions src/databricks/labs/ucx/contexts/account_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ def account_client(self) -> AccountClient:
return self._ac

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

@cached_property
def account_workspaces(self):
def account_workspaces(self) -> AccountWorkspaces:
return AccountWorkspaces(self.account_client, self.workspace_ids)

@cached_property
def account_aggregate(self):
def account_aggregate(self) -> AccountAggregate:
return AccountAggregate(self.account_workspaces)

@cached_property
def is_account_install(self):
def is_account_install(self) -> bool:
return environ.get("UCX_FORCE_INSTALL") == "account"

@cached_property
def account_metastores(self):
def account_metastores(self) -> AccountMetastores:
return AccountMetastores(self.account_client)
Loading

0 comments on commit 352126d

Please sign in to comment.