Skip to content

Commit

Permalink
fixing the typing
Browse files Browse the repository at this point in the history
  • Loading branch information
seperman committed Mar 5, 2025
1 parent c05467c commit 75c0cd9
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions deepdiff/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def to_json_pickle(self):
"""
try:
import jsonpickle
copied = self.copy()
copied = self.copy() # type: ignore
return jsonpickle.encode(copied)
except ImportError: # pragma: no cover. Json pickle is getting deprecated.
logger.error('jsonpickle library needs to be installed in order to run to_json_pickle') # pragma: no cover. Json pickle is getting deprecated.
Expand Down Expand Up @@ -210,8 +210,8 @@ def to_dict(self, view_override=None):
The options are the text or tree.
"""

view = view_override if view_override else self.view
return dict(self._get_view_results(view))
view = view_override if view_override else self.view # type: ignore
return dict(self._get_view_results(view)) # type: ignore

def _to_delta_dict(self, directed=True, report_repetition_required=True, always_include_values=False):
"""
Expand All @@ -236,12 +236,12 @@ def _to_delta_dict(self, directed=True, report_repetition_required=True, always_
was set to be True in the diff object.
"""
if self.group_by is not None:
if self.group_by is not None: # type: ignore
raise ValueError(DELTA_ERROR_WHEN_GROUP_BY)

if directed and not always_include_values:
_iterable_opcodes = {}
for path, op_codes in self._iterable_opcodes.items():
_iterable_opcodes = {} # type: ignore
for path, op_codes in self._iterable_opcodes.items(): # type: ignore
_iterable_opcodes[path] = []
for op_code in op_codes:
new_op_code = Opcode(
Expand All @@ -254,29 +254,29 @@ def _to_delta_dict(self, directed=True, report_repetition_required=True, always_
)
_iterable_opcodes[path].append(new_op_code)
else:
_iterable_opcodes = self._iterable_opcodes
_iterable_opcodes = self._iterable_opcodes # type: ignore

result = DeltaResult(
tree_results=self.tree,
ignore_order=self.ignore_order,
tree_results=self.tree, # type: ignore
ignore_order=self.ignore_order, # type: ignore
always_include_values=always_include_values,
_iterable_opcodes=_iterable_opcodes,
)
result.remove_empty_keys()
if report_repetition_required and self.ignore_order and not self.report_repetition:
if report_repetition_required and self.ignore_order and not self.report_repetition: # type: ignore
raise ValueError(DELTA_IGNORE_ORDER_NEEDS_REPETITION_REPORT)
if directed:
for report_key, report_value in result.items():
if isinstance(report_value, Mapping):
for path, value in report_value.items():
if isinstance(value, Mapping) and 'old_value' in value:
del value['old_value']
if self._numpy_paths:
del value['old_value'] # type: ignore
if self._numpy_paths: # type: ignore
# Note that keys that start with '_' are considered internal to DeepDiff
# and will be omitted when counting distance. (Look inside the distance module.)
result['_numpy_paths'] = self._numpy_paths
result['_numpy_paths'] = self._numpy_paths # type: ignore

if self.iterable_compare_func:
if self.iterable_compare_func: # type: ignore
result['_iterable_compare_func_was_used'] = True

return deepcopy(dict(result))
Expand All @@ -299,9 +299,9 @@ def pretty(self, prefix: Optional[Union[str, Callable]]=None):
result = []
if prefix is None:
prefix = ''
keys = sorted(self.tree.keys()) # sorting keys to guarantee constant order across python versions.
keys = sorted(self.tree.keys()) # type: ignore # sorting keys to guarantee constant order across python versions.
for key in keys:
for item_key in self.tree[key]:
for item_key in self.tree[key]: # type: ignore
result += [pretty_print_diff(item_key)]

if callable(prefix):
Expand Down Expand Up @@ -486,7 +486,7 @@ def load_path_content(path, file_type=None):
content = pickle_load(content)
elif file_type in {'csv', 'tsv'}:
try:
import clevercsv
import clevercsv # type: ignore
content = clevercsv.read_dicts(path)
except ImportError: # pragma: no cover.
import csv
Expand Down Expand Up @@ -633,7 +633,7 @@ class JSONDecoder(json.JSONDecoder):
def __init__(self, *args, **kwargs):
json.JSONDecoder.__init__(self, object_hook=self.object_hook, *args, **kwargs)

def object_hook(self, obj):
def object_hook(self, obj): # type: ignore
if 'old_type' in obj and 'new_type' in obj:
for type_key in ('old_type', 'new_type'):
type_str = obj[type_key]
Expand All @@ -648,7 +648,7 @@ def json_dumps(
force_use_builtin_json: bool = False,
return_bytes: bool = False,
**kwargs,
) -> str | bytes:
) -> Union[str, bytes]:
"""
Dump json with extra details that are not normally json serializable
Expand Down

0 comments on commit 75c0cd9

Please sign in to comment.