Skip to content

ci(pre-commit.ci): autoupdate #695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ ci:

repos:
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.23
rev: v0.24.1
hooks:
- id: validate-pyproject

- repo: https://github.com/crate-ci/typos
rev: v1.30.0
rev: v1
hooks:
- id: typos

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.9
rev: v0.11.4
hooks:
- id: ruff
args: ["--fix", "--unsafe-fixes"]
Expand Down
8 changes: 4 additions & 4 deletions src/magicgui/schema/_ui_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ def _get_values(obj: Any) -> dict | None:

# named tuple
if isinstance(obj, tuple) and hasattr(obj, "_asdict"):
return cast(dict, obj._asdict())
return cast("dict", obj._asdict())

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

# pydantic models
if hasattr(obj, "model_dump"):
return cast(dict, obj.model_dump())
return cast("dict", obj.model_dump())
elif hasattr(obj, "dict"):
return cast(dict, obj.dict())
return cast("dict", obj.dict())

return None

Expand Down
7 changes: 4 additions & 3 deletions src/magicgui/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import inspect
import typing
import warnings
from collections.abc import Sequence
from types import MappingProxyType
from typing import TYPE_CHECKING, Annotated, Any, Callable, cast

Expand All @@ -26,6 +25,8 @@
from magicgui.types import Undefined

if TYPE_CHECKING:
from collections.abc import Sequence

from typing_extensions import Unpack

from magicgui.application import AppRef
Expand Down Expand Up @@ -173,7 +174,7 @@ def __init__(
@property
def options(self) -> dict:
"""Return just this options part of the annotation."""
return cast(dict, get_args(self.annotation)[1])
return cast("dict", get_args(self.annotation)[1])

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

return type(self)(
cast(Sequence[inspect.Parameter], parameters),
cast("Sequence[inspect.Parameter]", parameters),
return_annotation=return_annotation,
)

Expand Down
2 changes: 1 addition & 1 deletion src/magicgui/tqdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def close(self) -> None:
if not self._in_visible_gui:
super().close()
return
self._mgui = cast(FunctionGui, self._mgui)
self._mgui = cast("FunctionGui", self._mgui)

if self.disable:
return
Expand Down
10 changes: 6 additions & 4 deletions src/magicgui/type_map/_type_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ def _register_widget(
widget_type: WidgetRef | None = None,
**options: Any,
) -> WidgetTuple | None:
_options = cast(dict, options)
_options = cast("dict", options)

previous_widget = self._type_defs.get(resolved_type)

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

return inner_func if function is None else inner_func(function)

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

mod_name, name = class_name.rsplit(".", 1)
mod = importlib.import_module(mod_name)
return cast(WidgetClass, getattr(mod, name))
return cast("WidgetClass", getattr(mod, name))


def _validate_return_callback(func: Callable) -> None:
Expand All @@ -1176,4 +1178,4 @@ def _generate_union_variants(type_: Any) -> Iterator[type]:
type_args = get_args(type_)
for i in range(2, len(type_args) + 1):
for per in itertools.combinations(type_args, i):
yield cast(type, Union[per])
yield cast("type", Union[per])
6 changes: 3 additions & 3 deletions src/magicgui/widgets/_concrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ def _append_value(self, value: _V | _Undefined = Undefined) -> None:
name=f"value_{i}",
options=self._child_options,
)
widget = _ListEditChildWidget(cast(BaseValueWidget, _value_widget))
widget = _ListEditChildWidget(cast("BaseValueWidget", _value_widget))

# connect the minus-button-clicked event
def _remove_me() -> None:
Expand Down Expand Up @@ -844,7 +844,7 @@ def __setitem__(self, key: slice, value: _V | Iterable[_V]) -> None: ...
def __setitem__(self, key: int | slice, value: _V | Iterable[_V]) -> None:
"""Update widget value."""
if isinstance(key, int):
self._obj._get_child_widget(key).value = cast(_V, value)
self._obj._get_child_widget(key).value = cast("_V", value)
elif isinstance(key, slice):
with self._obj.changed.blocked():
if isinstance(value, type(self._obj._get_child_widget(0).value)):
Expand Down Expand Up @@ -926,7 +926,7 @@ def __init__(
for a in _value:
i = len(self)
widget = cast(
BaseValueWidget,
"BaseValueWidget",
create_widget(
value=a,
annotation=self._args_types[i],
Expand Down
6 changes: 3 additions & 3 deletions src/magicgui/widgets/_function_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from magicgui._type_resolution import resolve_single_type
from magicgui.signature import MagicSignature, magic_signature
from magicgui.widgets import Container, MainWindow, ProgressBar, PushButton
from magicgui.widgets.bases import BaseValueWidget

if TYPE_CHECKING:
from collections.abc import Iterator
Expand All @@ -36,6 +35,7 @@
from magicgui.application import Application, AppRef # noqa: F401
from magicgui.type_map import TypeMap
from magicgui.widgets import TextEdit
from magicgui.widgets.bases import BaseValueWidget
from magicgui.widgets.protocols import ContainerProtocol, MainWindowProtocol

_P = ParamSpec("_P")
Expand Down Expand Up @@ -229,7 +229,7 @@
@self._call_button.changed.connect
def _disable_button_and_call() -> None:
# disable the call button until the function has finished
self._call_button = cast(PushButton, self._call_button)
self._call_button = cast("PushButton", self._call_button)

Check warning on line 232 in src/magicgui/widgets/_function_gui.py

View check run for this annotation

Codecov / codecov/patch

src/magicgui/widgets/_function_gui.py#L232

Added line #L232 was not covered by tests
self._call_button.enabled = False
try:
self.__call__() # type: ignore [call-arg]
Expand All @@ -241,7 +241,7 @@
self._result_widget: BaseValueWidget | None = None
if result_widget:
self._result_widget = cast(
BaseValueWidget,
"BaseValueWidget",
type_map.create_widget(
value=None,
annotation=self._return_annotation,
Expand Down
2 changes: 1 addition & 1 deletion src/magicgui/widgets/_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def shape(self) -> tuple[int, int]:
@property
def size(self) -> int:
"""Return shape of table widget (rows, cols)."""
return cast(int, operator.mul(*self.shape))
return cast("int", operator.mul(*self.shape))

def keys(self, axis: str = "column") -> HeadersView[TblKey]:
"""Return a set-like object providing a view on this table's headers."""
Expand Down
2 changes: 1 addition & 1 deletion src/magicgui/widgets/bases/_categorical_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@

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

Check warning on line 111 in src/magicgui/widgets/bases/_categorical_widget.py

View check run for this annotation

Codecov / codecov/patch

src/magicgui/widgets/bases/_categorical_widget.py#L111

Added line #L111 was not covered by tests

def set_choice(self, choice_name: str, data: Any | None = None) -> None:
"""Set data for the provided ``choice_name``."""
Expand Down
2 changes: 1 addition & 1 deletion src/magicgui/widgets/bases/_container_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def __init__(
**base_widget_kwargs,
)
if value is not Undefined:
self.value = cast(T, value)
self.value = cast("T", value)
if self._bound_value is not Undefined and "visible" not in base_widget_kwargs:
self.hide()

Expand Down
2 changes: 1 addition & 1 deletion src/magicgui/widgets/bases/_ranged_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(
self.step = None
self._widget._mgui_set_step(1)
else:
self.step = cast(float, step)
self.step = cast("float", step)

self.min, self.max = self._init_range(value, min, max)
if value is not None and not isinstance(value, _Undefined):
Expand Down
6 changes: 3 additions & 3 deletions src/magicgui/widgets/bases/_value_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(
self._call_bound: bool = True
super().__init__(**base_widget_kwargs)
if value is not Undefined:
self.value = cast(T, value)
self.value = cast("T", value)
if self._bound_value is not Undefined and "visible" not in base_widget_kwargs:
self.hide()

Expand Down Expand Up @@ -95,7 +95,7 @@ def value(self) -> T:
"access `widget.value` in your bound callback, use "
"`widget.get_value()`"
) from e
return cast(T, self._bound_value)
return cast("T", self._bound_value)
return self.get_value()

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

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