Skip to content

Commit c6bb435

Browse files
style(pre-commit.ci): auto fixes [...]
1 parent 0bc3305 commit c6bb435

11 files changed

+28
-25
lines changed

src/magicgui/schema/_ui_field.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ def _get_values(obj: Any) -> dict | None:
828828

829829
# named tuple
830830
if isinstance(obj, tuple) and hasattr(obj, "_asdict"):
831-
return cast(dict, obj._asdict())
831+
return cast("dict", obj._asdict())
832832

833833
# dataclass
834834
if dc.is_dataclass(type(obj)):
@@ -837,13 +837,13 @@ def _get_values(obj: Any) -> dict | None:
837837
# attrs
838838
attr = sys.modules.get("attr")
839839
if attr is not None and attr.has(obj):
840-
return cast(dict, attr.asdict(obj))
840+
return cast("dict", attr.asdict(obj))
841841

842842
# pydantic models
843843
if hasattr(obj, "model_dump"):
844-
return cast(dict, obj.model_dump())
844+
return cast("dict", obj.model_dump())
845845
elif hasattr(obj, "dict"):
846-
return cast(dict, obj.dict())
846+
return cast("dict", obj.dict())
847847

848848
return None
849849

src/magicgui/signature.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import inspect
1818
import typing
1919
import warnings
20-
from collections.abc import Sequence
2120
from types import MappingProxyType
2221
from typing import TYPE_CHECKING, Annotated, Any, Callable, cast
2322

@@ -26,6 +25,8 @@
2625
from magicgui.types import Undefined
2726

2827
if TYPE_CHECKING:
28+
from collections.abc import Sequence
29+
2930
from typing_extensions import Unpack
3031

3132
from magicgui.application import AppRef
@@ -173,7 +174,7 @@ def __init__(
173174
@property
174175
def options(self) -> dict:
175176
"""Return just this options part of the annotation."""
176-
return cast(dict, get_args(self.annotation)[1])
177+
return cast("dict", get_args(self.annotation)[1])
177178

178179
def __repr__(self) -> str:
179180
"""Return __repr__, replacing NoneType if present."""
@@ -334,7 +335,7 @@ def replace( # type: ignore[override]
334335
return_annotation = self.return_annotation
335336

336337
return type(self)(
337-
cast(Sequence[inspect.Parameter], parameters),
338+
cast("Sequence[inspect.Parameter]", parameters),
338339
return_annotation=return_annotation,
339340
)
340341

src/magicgui/tqdm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def close(self) -> None:
148148
if not self._in_visible_gui:
149149
super().close()
150150
return
151-
self._mgui = cast(FunctionGui, self._mgui)
151+
self._mgui = cast("FunctionGui", self._mgui)
152152

153153
if self.disable:
154154
return

src/magicgui/type_map/_type_map.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ def _register_widget(
10131013
widget_type: WidgetRef | None = None,
10141014
**options: Any,
10151015
) -> WidgetTuple | None:
1016-
_options = cast(dict, options)
1016+
_options = cast("dict", options)
10171017

10181018
previous_widget = self._type_defs.get(resolved_type)
10191019

@@ -1074,7 +1074,9 @@ def inner_func(func: Callable) -> widgets.FunctionGui | MagicFactory:
10741074
)
10751075
# MagicFactory is unnecessary if we are immediately instantiating the
10761076
# widget, so we shortcut that and just return the FunctionGui here.
1077-
return cast(widgets.FunctionGui, magic_class(func, type_map=self, **kwargs))
1077+
return cast(
1078+
"widgets.FunctionGui", magic_class(func, type_map=self, **kwargs)
1079+
)
10781080

10791081
return inner_func if function is None else inner_func(function)
10801082

@@ -1160,7 +1162,7 @@ def _import_wdg_class(class_name: str) -> WidgetClass:
11601162

11611163
mod_name, name = class_name.rsplit(".", 1)
11621164
mod = importlib.import_module(mod_name)
1163-
return cast(WidgetClass, getattr(mod, name))
1165+
return cast("WidgetClass", getattr(mod, name))
11641166

11651167

11661168
def _validate_return_callback(func: Callable) -> None:
@@ -1176,4 +1178,4 @@ def _generate_union_variants(type_: Any) -> Iterator[type]:
11761178
type_args = get_args(type_)
11771179
for i in range(2, len(type_args) + 1):
11781180
for per in itertools.combinations(type_args, i):
1179-
yield cast(type, Union[per])
1181+
yield cast("type", Union[per])

src/magicgui/widgets/_concrete.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ def _append_value(self, value: _V | _Undefined = Undefined) -> None:
745745
name=f"value_{i}",
746746
options=self._child_options,
747747
)
748-
widget = _ListEditChildWidget(cast(BaseValueWidget, _value_widget))
748+
widget = _ListEditChildWidget(cast("BaseValueWidget", _value_widget))
749749

750750
# connect the minus-button-clicked event
751751
def _remove_me() -> None:
@@ -844,7 +844,7 @@ def __setitem__(self, key: slice, value: _V | Iterable[_V]) -> None: ...
844844
def __setitem__(self, key: int | slice, value: _V | Iterable[_V]) -> None:
845845
"""Update widget value."""
846846
if isinstance(key, int):
847-
self._obj._get_child_widget(key).value = cast(_V, value)
847+
self._obj._get_child_widget(key).value = cast("_V", value)
848848
elif isinstance(key, slice):
849849
with self._obj.changed.blocked():
850850
if isinstance(value, type(self._obj._get_child_widget(0).value)):
@@ -926,7 +926,7 @@ def __init__(
926926
for a in _value:
927927
i = len(self)
928928
widget = cast(
929-
BaseValueWidget,
929+
"BaseValueWidget",
930930
create_widget(
931931
value=a,
932932
annotation=self._args_types[i],

src/magicgui/widgets/_function_gui.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from magicgui._type_resolution import resolve_single_type
2626
from magicgui.signature import MagicSignature, magic_signature
2727
from magicgui.widgets import Container, MainWindow, ProgressBar, PushButton
28-
from magicgui.widgets.bases import BaseValueWidget
2928

3029
if TYPE_CHECKING:
3130
from collections.abc import Iterator
@@ -36,6 +35,7 @@
3635
from magicgui.application import Application, AppRef # noqa: F401
3736
from magicgui.type_map import TypeMap
3837
from magicgui.widgets import TextEdit
38+
from magicgui.widgets.bases import BaseValueWidget
3939
from magicgui.widgets.protocols import ContainerProtocol, MainWindowProtocol
4040

4141
_P = ParamSpec("_P")
@@ -229,7 +229,7 @@ def __init__(
229229
@self._call_button.changed.connect
230230
def _disable_button_and_call() -> None:
231231
# disable the call button until the function has finished
232-
self._call_button = cast(PushButton, self._call_button)
232+
self._call_button = cast("PushButton", self._call_button)
233233
self._call_button.enabled = False
234234
try:
235235
self.__call__() # type: ignore [call-arg]
@@ -241,7 +241,7 @@ def _disable_button_and_call() -> None:
241241
self._result_widget: BaseValueWidget | None = None
242242
if result_widget:
243243
self._result_widget = cast(
244-
BaseValueWidget,
244+
"BaseValueWidget",
245245
type_map.create_widget(
246246
value=None,
247247
annotation=self._return_annotation,

src/magicgui/widgets/_table.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def shape(self) -> tuple[int, int]:
364364
@property
365365
def size(self) -> int:
366366
"""Return shape of table widget (rows, cols)."""
367-
return cast(int, operator.mul(*self.shape))
367+
return cast("int", operator.mul(*self.shape))
368368

369369
def keys(self, axis: str = "column") -> HeadersView[TblKey]:
370370
"""Return a set-like object providing a view on this table's headers."""

src/magicgui/widgets/bases/_categorical_widget.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def __len__(self) -> int:
108108

109109
def get_choice(self, choice_name: str) -> T:
110110
"""Get data for the provided ``choice_name``."""
111-
return cast(T, self._widget._mgui_get_choice(choice_name))
111+
return cast("T", self._widget._mgui_get_choice(choice_name))
112112

113113
def set_choice(self, choice_name: str, data: Any | None = None) -> None:
114114
"""Set data for the provided ``choice_name``."""

src/magicgui/widgets/bases/_container_widget.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def __init__(
265265
**base_widget_kwargs,
266266
)
267267
if value is not Undefined:
268-
self.value = cast(T, value)
268+
self.value = cast("T", value)
269269
if self._bound_value is not Undefined and "visible" not in base_widget_kwargs:
270270
self.hide()
271271

src/magicgui/widgets/bases/_ranged_widget.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def __init__(
7373
self.step = None
7474
self._widget._mgui_set_step(1)
7575
else:
76-
self.step = cast(float, step)
76+
self.step = cast("float", step)
7777

7878
self.min, self.max = self._init_range(value, min, max)
7979
if value is not None and not isinstance(value, _Undefined):

src/magicgui/widgets/bases/_value_widget.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def __init__(
5858
self._call_bound: bool = True
5959
super().__init__(**base_widget_kwargs)
6060
if value is not Undefined:
61-
self.value = cast(T, value)
61+
self.value = cast("T", value)
6262
if self._bound_value is not Undefined and "visible" not in base_widget_kwargs:
6363
self.hide()
6464

@@ -95,7 +95,7 @@ def value(self) -> T:
9595
"access `widget.value` in your bound callback, use "
9696
"`widget.get_value()`"
9797
) from e
98-
return cast(T, self._bound_value)
98+
return cast("T", self._bound_value)
9999
return self.get_value()
100100

101101
@value.setter
@@ -200,7 +200,7 @@ def get_value(self) -> T:
200200
an escape hatch if trying to access the widget's value inside of a callback
201201
bound to self._bound_value.
202202
"""
203-
return cast(T, self._widget._mgui_get_value())
203+
return cast("T", self._widget._mgui_get_value())
204204

205205
def set_value(self, value: Any) -> None:
206206
self._widget._mgui_set_value(value)

0 commit comments

Comments
 (0)