Skip to content

Commit

Permalink
Ignore mypy errors related to CueWidget (#98)
Browse files Browse the repository at this point in the history
mypy cannot infer the correct type of traits_to_observe in CueWidget init
constructor after if checks so we ignore it. Further there are problems with
types of List[A | B] when wants to assign them with a variable of type List[A].
We ignore these cases too.

Fix types from `Union[List[str], List[Sentinel], List[List[str]]]` to
`List[Union[str, Sentinel, List[str]]]`.
  • Loading branch information
agoscinski authored Dec 18, 2024
1 parent 1a00805 commit 0c30bdb
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/scwidgets/cue/_widget_cue.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def set_widgets_to_observe(
"traits_to_observe cannot contain lists when "
"widgets_to_observe is not a list."
)
traits_to_observe = [traits_to_observe]
traits_to_observe = [traits_to_observe] # type: ignore[list-item]
else:
if not (isinstance(traits_to_observe, list)):
raise ValueError(
Expand Down
16 changes: 12 additions & 4 deletions src/scwidgets/cue/_widget_cue_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class CueBox(VBox, CueWidget):
def __init__(
self,
widgets_to_observe: Union[List[Widget], Widget],
traits_to_observe: Union[str, List[str], List[List[str]], Sentinel] = "value",
traits_to_observe: Union[
str, Sentinel, List[Union[str, Sentinel, List[str]]]
] = "value",
widget_to_cue: Optional[Widget] = None,
cued: bool = True,
css_style: Optional[dict] = None,
Expand Down Expand Up @@ -112,7 +114,9 @@ class SaveCueBox(CueBox):
def __init__(
self,
widgets_to_observe: Widget,
traits_to_observe: Union[str, List[str], Sentinel] = "value",
traits_to_observe: Union[
str, Sentinel, List[Union[str, Sentinel, List[str]]]
] = "value",
widget_to_cue: Optional[Widget] = None,
cued: bool = True,
*args,
Expand Down Expand Up @@ -151,7 +155,9 @@ class CheckCueBox(CueBox):
def __init__(
self,
widgets_to_observe: Widget,
traits_to_observe: Union[str, List[str], Sentinel] = "value",
traits_to_observe: Union[
str, Sentinel, List[Union[str, Sentinel, List[str]]]
] = "value",
widget_to_cue: Optional[Widget] = None,
cued: bool = True,
*args,
Expand Down Expand Up @@ -190,7 +196,9 @@ class UpdateCueBox(CueBox):
def __init__(
self,
widgets_to_observe: Widget,
traits_to_observe: Union[str, List[str], Sentinel] = "value",
traits_to_observe: Union[
str, Sentinel, List[Union[str, Sentinel, List[str]]]
] = "value",
widget_to_cue: Optional[Widget] = None,
cued: bool = True,
*args,
Expand Down
2 changes: 1 addition & 1 deletion src/scwidgets/cue/_widget_cue_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(
figure: Figure,
widgets_to_observe: Union[None, List[Widget], Widget] = None,
traits_to_observe: Union[
None, str, List[str], List[List[str]], Sentinel
None, str, Sentinel, List[Union[str, Sentinel, List[str]]]
] = None,
cued: bool = True,
show_toolbars: bool = False,
Expand Down
2 changes: 1 addition & 1 deletion src/scwidgets/cue/_widget_cue_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(
object: Any = None,
widgets_to_observe: Union[None, List[Widget], Widget] = None,
traits_to_observe: Union[
None, str, List[str], List[List[str]], Sentinel
None, str, Sentinel, List[Union[str, Sentinel, List[str]]]
] = None,
cued: bool = True,
css_style: Optional[dict] = None,
Expand Down
2 changes: 1 addition & 1 deletion src/scwidgets/cue/_widget_cue_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(
self,
widgets_to_observe: Union[None, List[Widget], Widget] = None,
traits_to_observe: Union[
None, str, List[str], List[List[str]], Sentinel
None, str, Sentinel, List[Union[str, Sentinel, List[str]]]
] = None,
cued: bool = True,
css_style: Optional[dict] = None,
Expand Down
7 changes: 3 additions & 4 deletions src/scwidgets/exercise/_widget_code_exercise.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def __init__(

self._cue_parameter_panel = UpdateCueBox(
self._parameter_panel.parameters_widget,
self._parameter_panel.parameters_trait,
self._parameter_panel.parameters_trait, # type: ignore
self._parameter_panel,
)

Expand Down Expand Up @@ -362,7 +362,6 @@ def __init__(
else:
description = "Update"
button_tooltip = "Updates outputs with the specified parameters"

self._update_button = UpdateResetCueButton(
reset_update_cue_widgets, # type: ignore[arg-type]
self._on_click_update_action,
Expand All @@ -374,7 +373,7 @@ def __init__(
update_button_disable_during_action,
),
widgets_to_observe=widgets_to_observe,
traits_to_observe=traits_to_observe,
traits_to_observe=traits_to_observe, # type: ignore[arg-type]
description=description,
button_tooltip=button_tooltip,
cued=True,
Expand Down Expand Up @@ -403,7 +402,7 @@ def __init__(
if self._cue_code is not None:
self._cue_code = SaveCueBox(
save_widgets_to_observe,
save_traits_to_observe,
save_traits_to_observe, # type: ignore[arg-type]
self._cue_code,
cued=True,
)
Expand Down

0 comments on commit 0c30bdb

Please sign in to comment.