Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: add typing for merge and value_strategy functions #33

Merged
merged 1 commit into from
Aug 30, 2024
Merged
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
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