Skip to content

Commit

Permalink
feat: add typing for merge and value_strategy functions (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
Atry authored Aug 30, 2024
1 parent 4e1f31e commit 31c2aa9
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions deepmerge/merger.py
Original file line number Diff line number Diff line change
@@ -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:
"""
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 31c2aa9

Please # to comment.