From cc5bbbb4474f4c6550c81ff7eea267a2a75847c0 Mon Sep 17 00:00:00 2001 From: "Yang, Bo" Date: Thu, 6 Jun 2024 18:53:06 +0000 Subject: [PATCH] feat: add typing for `merge` and `value_strategy` functions --- deepmerge/merger.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/deepmerge/merger.py b/deepmerge/merger.py index 6c85ff9..a200f43 100644 --- a/deepmerge/merger.py +++ b/deepmerge/merger.py @@ -1,9 +1,10 @@ from __future__ import annotations -from typing import Any, Sequence, Callable +from typing import Any, Sequence, TypeVar from . import strategy as s +_T = TypeVar("_T") class Merger: """ @@ -39,13 +40,13 @@ def __init__( raise ValueError(f"Cannot handle ({typ}, {strategy})") return - def merge(self, base: Any, nxt: Any) -> Any: + def merge(self, base: _T, nxt: _T) -> _T: return self.value_strategy([], base, nxt) def type_conflict_strategy(self, path: list, base: Any, nxt: Any) -> Any: return self._type_conflict_strategy(self, path, base, nxt) - def value_strategy(self, path: list, base: Any, nxt: Any) -> Any: + def value_strategy(self, path: list, base: _T, nxt: _T) -> _T: # Check for strategy based on type of base, next for typ, strategy in self._type_strategies: if isinstance(base, typ) and isinstance(nxt, typ):