Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
antonymilne committed Dec 2, 2024
1 parent 49236ab commit b92bcdd
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
4 changes: 2 additions & 2 deletions vizro-core/src/vizro/_vizro.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from collections.abc import Iterable
from contextlib import suppress
from pathlib import Path, PurePosixPath
from typing import TYPE_CHECKING, TypedDict
from typing import TYPE_CHECKING, TypedDict, cast

import dash
import plotly.io as pio
Expand Down Expand Up @@ -145,7 +145,7 @@ def _pre_build():
# Any models that are created during the pre-build process *will not* themselves have pre_build run on them.
# In future may add a second pre_build loop after the first one.

for filter in model_manager._get_models(Filter):
for filter in cast(Iterable[Filter], model_manager._get_models(Filter)):
# Run pre_build on all filters first, then on all other models. This handles dependency between Filter
# and Page pre_build and ensures that filters are pre-built before the Page objects that use them.
# This is important because the Page pre_build method checks whether filters are dynamic or not, which is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ def _get_export_data_callback_outputs(action: Action) -> dict[str, Output]:
targets = None

targets = targets or [
model.id for model in model_manager._get_models(FIGURE_MODELS, model_manager._get_model_page(action))
model.id
for model in cast(
Iterable[VizroBaseModel], model_manager._get_models(FIGURE_MODELS, model_manager._get_model_page(action))
)
]

return {
Expand All @@ -138,7 +141,10 @@ def _get_export_data_callback_components(action: Action) -> list[dcc.Download]:
targets = None

targets = targets or [
model.id for model in model_manager._get_models(FIGURE_MODELS, model_manager._get_model_page(action))
model.id
for model in cast(
Iterable[VizroBaseModel], model_manager._get_models(FIGURE_MODELS, model_manager._get_model_page(action))
)
]

return [
Expand Down
6 changes: 3 additions & 3 deletions vizro-core/src/vizro/managers/_model_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import random
import uuid
from collections.abc import Generator
from typing import TYPE_CHECKING, NewType, Optional, TypeVar, Union
from collections.abc import Generator, Iterable
from typing import TYPE_CHECKING, NewType, Optional, TypeVar, Union, cast

from vizro.managers._managers_utils import _state_modifier

Expand Down Expand Up @@ -119,7 +119,7 @@ def _get_model_page(self, model: Model) -> Page: # type: ignore[return]
if isinstance(model, Page):
return model

for page in self._get_models(Page):
for page in cast(Iterable[Page], self._get_models(Page)):
if model in self.__get_model_children(page):
return page

Expand Down
7 changes: 5 additions & 2 deletions vizro-core/src/vizro/models/_controls/filter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Any, Literal, Union
from typing import Any, Literal, Union, cast, Iterable

import pandas as pd
from dash import dcc
Expand Down Expand Up @@ -137,7 +137,10 @@ def pre_build(self):
# This is the case when bool(self.targets) is False.
# Possibly in future this will change (which would be breaking change).
proposed_targets = self.targets or [
model.id for model in model_manager._get_models(FIGURE_MODELS, model_manager._get_model_page(self))
cast(ModelID, model.id)
for model in cast(
Iterable[VizroBaseModel], model_manager._get_models(FIGURE_MODELS, model_manager._get_model_page(self))
)
]
# TODO: Currently dynamic data functions require a default value for every argument. Even when there is a
# dataframe parameter, the default value is used when pre-build the filter e.g. to find the targets,
Expand Down
4 changes: 2 additions & 2 deletions vizro-core/src/vizro/models/_navigation/_navigation_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import itertools
from typing import TypedDict
from typing import TypedDict, cast, Iterable

import dash_bootstrap_components as dbc

Expand All @@ -15,7 +15,7 @@ def _validate_pages(pages):
pages_as_list = list(itertools.chain(*pages.values())) if isinstance(pages, dict) else pages
# Ideally we would use dashboard.pages in the model manager here, but we only register pages in
# dashboard.pre_build and model manager cannot find a Dashboard at validation time.
registered_pages = [page.id for page in model_manager._get_models(Page)]
registered_pages = [page.id for page in cast(Iterable[Page], model_manager._get_models(Page))]

if not pages_as_list:
raise ValueError("Ensure this value has at least 1 item.")
Expand Down
4 changes: 3 additions & 1 deletion vizro-core/src/vizro/models/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ def __vizro_exclude_fields__(self) -> Optional[Union[set[str], Mapping[str, Any]

@_log_call
def pre_build(self):
figure_targets = [model.id for model in model_manager._get_models(FIGURE_MODELS, page=self)]
figure_targets = [
model.id for model in cast(Iterable[VizroBaseModel], model_manager._get_models(FIGURE_MODELS, page=self))
]
filter_targets = [
filter.id
for filter in cast(Iterable[Filter], model_manager._get_models(Filter, page=self))
Expand Down

0 comments on commit b92bcdd

Please sign in to comment.