From c7e2d163ae249f3b80396ac41e6b1bb73ac93f0e Mon Sep 17 00:00:00 2001 From: DeviousStoat Date: Sun, 3 Mar 2024 22:33:32 +0100 Subject: [PATCH] Rename apply_catch --- src/pydash/__init__.py | 4 ++-- src/pydash/chaining/all_funcs.pyi | 12 ++++++------ src/pydash/objects.py | 14 +++++++------- tests/pytest_mypy_testing/test_objects.py | 4 ++-- tests/test_objects.py | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/pydash/__init__.py b/src/pydash/__init__.py index 5c9686c..0b9df28 100644 --- a/src/pydash/__init__.py +++ b/src/pydash/__init__.py @@ -169,9 +169,9 @@ ) from .objects import ( apply, + apply_catch, apply_if, apply_if_not_none, - apply_ignore_excs, assign, assign_with, callables, @@ -548,9 +548,9 @@ "variance", "zscore", "apply", + "apply_catch", "apply_if", "apply_if_not_none", - "apply_ignore_excs", "assign", "assign_with", "callables", diff --git a/src/pydash/chaining/all_funcs.pyi b/src/pydash/chaining/all_funcs.pyi index b5472e7..ee9f96f 100644 --- a/src/pydash/chaining/all_funcs.pyi +++ b/src/pydash/chaining/all_funcs.pyi @@ -2556,21 +2556,21 @@ class AllFuncs: return self._wrap(pyd.apply_if_not_none)(func) @t.overload - def apply_ignore_excs( + def apply_catch( self: "Chain[T]", func: t.Callable[[T], T2], exceptions: t.Iterable[t.Type[Exception]], - fallback: T3, + default: T3, ) -> "Chain[t.Union[T2, T3]]": ... @t.overload - def apply_ignore_excs( + def apply_catch( self: "Chain[T]", func: t.Callable[[T], T2], exceptions: t.Iterable[t.Type[Exception]], - fallback: Unset = UNSET, + default: Unset = UNSET, ) -> "Chain[t.Union[T, T2]]": ... - def apply_ignore_excs(self, func, exceptions, fallback=UNSET): - return self._wrap(pyd.apply_ignore_excs)(func, exceptions, fallback) + def apply_catch(self, func, exceptions, default=UNSET): + return self._wrap(pyd.apply_catch)(func, exceptions, default) @t.overload def merge( diff --git a/src/pydash/objects.py b/src/pydash/objects.py index 112f5f5..82a32c4 100644 --- a/src/pydash/objects.py +++ b/src/pydash/objects.py @@ -24,7 +24,7 @@ "apply", "apply_if", "apply_if_not_none", - "apply_ignore_excs", + "apply_catch", "assign", "assign_with", "callables", @@ -1394,14 +1394,14 @@ def apply_if_not_none(obj: t.Optional[T], func: t.Callable[[T], T2]) -> t.Option @t.overload -def apply_ignore_excs( +def apply_catch( obj: T, func: t.Callable[[T], T2], exceptions: t.Iterable[t.Type[Exception]], default: T3 ) -> t.Union[T2, T3]: ... @t.overload -def apply_ignore_excs( +def apply_catch( obj: T, func: t.Callable[[T], T2], exceptions: t.Iterable[t.Type[Exception]], @@ -1410,7 +1410,7 @@ def apply_ignore_excs( ... -def apply_ignore_excs(obj, func, exceptions, default=UNSET): +def apply_catch(obj, func, exceptions, default=UNSET): """ Tries to apply `func` to `obj` if any of the exceptions in `excs` are raised, return `default` or `obj` if not set. @@ -1426,11 +1426,11 @@ def apply_ignore_excs(obj, func, exceptions, default=UNSET): Example: - >>> apply_ignore_excs(2, lambda x: x * 2, [ValueError]) + >>> apply_catch(2, lambda x: x * 2, [ValueError]) 4 - >>> apply_ignore_excs(2, lambda x: x / 0, [ZeroDivisionError], "error") + >>> apply_catch(2, lambda x: x / 0, [ZeroDivisionError], "error") 'error' - >>> apply_ignore_excs(2, lambda x: x / 0, [ZeroDivisionError]) + >>> apply_catch(2, lambda x: x / 0, [ZeroDivisionError]) 2 .. versionadded:: 8.0.0 diff --git a/tests/pytest_mypy_testing/test_objects.py b/tests/pytest_mypy_testing/test_objects.py index b34a9f9..b459bc5 100644 --- a/tests/pytest_mypy_testing/test_objects.py +++ b/tests/pytest_mypy_testing/test_objects.py @@ -368,5 +368,5 @@ def test_mypy_apply_if_not_none() -> None: @pytest.mark.mypy_testing def test_mypy_apply_ignore_excs() -> None: - reveal_type(_.apply_ignore_excs(5, lambda x: x / 0, [ZeroDivisionError])) # R: Union[builtins.int, builtins.float] - reveal_type(_.apply_ignore_excs(5, lambda x: x / 0, [ZeroDivisionError], "error")) # R: Union[builtins.float, builtins.str] + reveal_type(_.apply_catch(5, lambda x: x / 0, [ZeroDivisionError])) # R: Union[builtins.int, builtins.float] + reveal_type(_.apply_catch(5, lambda x: x / 0, [ZeroDivisionError], "error")) # R: Union[builtins.float, builtins.str] diff --git a/tests/test_objects.py b/tests/test_objects.py index f460129..df1d07a 100644 --- a/tests/test_objects.py +++ b/tests/test_objects.py @@ -969,4 +969,4 @@ def test_apply_if_not_none(case, expected): [((5, lambda x: x * 2, [ValueError]), 10), ((5, lambda x: x / 0, [ZeroDivisionError]), 5)], ) def test_apply_ignore_excs(case, expected): - assert _.apply_ignore_excs(*case) == expected + assert _.apply_catch(*case) == expected