Skip to content

Commit 0fcaca4

Browse files
committed
better types
1 parent 4dbcbb4 commit 0fcaca4

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

deepdiff/base.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1+
from typing import Protocol, Any
12
from deepdiff.helper import strings, numbers, SetOrdered
23

34

45
DEFAULT_SIGNIFICANT_DIGITS_WHEN_IGNORE_NUMERIC_TYPES = 12
56
TYPE_STABILIZATION_MSG = 'Unable to stabilize the Numpy array {} due to {}. Please set ignore_order=False.'
67

78

8-
class Base:
9+
class BaseProtocol(Protocol):
10+
t1: Any
11+
t2: Any
12+
cutoff_distance_for_pairs: float
13+
use_log_scale: bool
14+
log_scale_similarity_threshold: float
15+
view: str
16+
17+
18+
class Base(BaseProtocol):
919
numbers = numbers
1020
strings = strings
1121

deepdiff/distance.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import math
22
import datetime
3+
from deepdiff.base import BaseProtocol
34
from deepdiff.deephash import DeepHash
45
from deepdiff.helper import (
56
DELTA_VIEW, numbers, strings, add_to_frozen_set, not_found, only_numbers, np, np_float64, time_to_seconds,
@@ -11,7 +12,9 @@
1112
DISTANCE_CALCS_NEEDS_CACHE = "Distance calculation can not happen once the cache is purged. Try with _cache='keep'"
1213

1314

14-
class DistanceMixin:
15+
16+
17+
class DistanceMixin(BaseProtocol):
1518

1619
def _get_rough_distance(self):
1720
"""

deepdiff/serialization.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def to_json(self, default_mapping: Optional[dict]=None, force_use_builtin_json=F
202202
**kwargs,
203203
)
204204

205-
def to_dict(self, view_override=None):
205+
def to_dict(self, view_override: Optional[str]=None) -> dict:
206206
"""
207207
convert the result to a python dictionary. You can override the view type by passing view_override.
208208
@@ -216,7 +216,12 @@ def to_dict(self, view_override=None):
216216
view = view_override if view_override else self.view # type: ignore
217217
return dict(self._get_view_results(view)) # type: ignore
218218

219-
def _to_delta_dict(self, directed=True, report_repetition_required=True, always_include_values=False):
219+
def _to_delta_dict(
220+
self,
221+
directed: bool = True,
222+
report_repetition_required: bool = True,
223+
always_include_values: bool = False,
224+
) -> dict:
220225
"""
221226
Dump to a dictionary suitable for delta usage.
222227
Unlike to_dict, this is not dependent on the original view that the user chose to create the diff.

0 commit comments

Comments
 (0)