Skip to content
Snippets Groups Projects
Commit caf2a942 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

MAINT: deprecate old arguments

parent eb30b29e
No related branches found
No related tags found
2 merge requests!159Release 0.16.o,!154Added the possibility to use custom labels instead of 'old' and 'new'
Pipeline #57458 failed
...@@ -622,11 +622,14 @@ def merge_entities(entity_a: Entity, ...@@ -622,11 +622,14 @@ def merge_entities(entity_a: Entity,
return entity_a return entity_a
def describe_diff(olddiff: dict[str, Any], newdiff: dict[str, Any], def describe_diff(entity0_diff: dict[str, Any], entity1_diff: dict[str, Any],
name: str = None, name: Optional[str] = None,
as_update: bool = True, as_update: Optional[bool] = None,
label_old: str = "old version", label_e0: str = "first version",
label_new: str = "new version") -> str: label_e1: str = "second version",
olddiff: Any = None,
newdiff: Any = None,
) -> str:
""" """
Generate a textual description of the differences between two entities. Generate a textual description of the differences between two entities.
These can be generated using :func:`compare_entities` and used within this function like this: These can be generated using :func:`compare_entities` and used within this function like this:
...@@ -636,25 +639,25 @@ def describe_diff(olddiff: dict[str, Any], newdiff: dict[str, Any], ...@@ -636,25 +639,25 @@ def describe_diff(olddiff: dict[str, Any], newdiff: dict[str, Any],
Arguments: Arguments:
---------- ----------
olddiff: dict[str, Any] entity0_diff: dict[str, Any]
First element of the tuple output of :func:`compare_entities`. First element of the tuple output of :func:`compare_entities`.
This is referred to as the "old" version. This is referred to as the "old" version.
newdiff: dict[str, Any] entity1_diff: dict[str, Any]
Second element of the tuple output of :func:`compare_entities`. Second element of the tuple output of :func:`compare_entities`.
This is referred to as the "new" version. This is referred to as the "new" version.
name: str name: Optional[str]
Default None. Name of the entity that will be shown in the output text. Default None. Name of the entity that will be shown in the output text.
as_update: bool as_update: Optional[bool]
Default True. Not used anymore. Default None. Not used anymore.
label_old: str label_e0: str
Can be used to set a custom label for the diff that is associated with the old entity. Can be used to set a custom label for the diff that is associated with the old entity.
label_new: str label_e1: str
Can be used to set a custom label for the diff that is associated with the new entity. Can be used to set a custom label for the diff that is associated with the new entity.
Returns: Returns:
...@@ -664,42 +667,51 @@ def describe_diff(olddiff: dict[str, Any], newdiff: dict[str, Any], ...@@ -664,42 +667,51 @@ def describe_diff(olddiff: dict[str, Any], newdiff: dict[str, Any],
""" """
description = "" description = ""
for attr in list(set(list(olddiff.keys()) + list(newdiff.keys()))): if as_update:
warnings.warn("'as_update' is deprecated. Do not use it.", DeprecationWarning)
if olddiff:
warnings.warn("'olddiff' is deprecated. Use 'entity0_diff' instead.", DeprecationWarning)
entity0_diff=olddiff
if newdiff:
warnings.warn("'newdiff' is deprecated. Use 'entity1_diff' instead.", DeprecationWarning)
entity1_diff=newdiff
for attr in list(set(list(entity0_diff.keys()) + list(entity1_diff.keys()))):
if attr == "parents" or attr == "properties": if attr == "parents" or attr == "properties":
continue continue
description += "{} differs:\n".format(attr) description += "{} differs:\n".format(attr)
description += label_old + ": {}\n".format( description += label_e0 + ": {}\n".format(
olddiff[attr] if attr in olddiff else "not set") entity0_diff[attr] if attr in entity0_diff else "not set")
description += label_new + ": {}\n\n".format( description += label_e1 + ": {}\n\n".format(
newdiff[attr] if attr in newdiff else "not set") entity1_diff[attr] if attr in entity1_diff else "not set")
if len(olddiff["parents"]) > 0: if len(entity0_diff["parents"]) > 0:
description += ("Parents that are only in the " + label_old + ":\n" description += ("Parents that are only in the " + label_e0 + ":\n"
+ ", ".join(olddiff["parents"]) + "\n") + ", ".join(entity0_diff["parents"]) + "\n")
if len(newdiff["parents"]) > 0: if len(entity1_diff["parents"]) > 0:
description += ("Parents that are only in the " + label_new + ":\n" description += ("Parents that are only in the " + label_e1 + ":\n"
+ ", ".join(olddiff["parents"]) + "\n") + ", ".join(entity0_diff["parents"]) + "\n")
for prop in list(set(list(olddiff["properties"].keys()) for prop in list(set(list(entity0_diff["properties"].keys())
+ list(newdiff["properties"].keys()))): + list(entity1_diff["properties"].keys()))):
description += "property {} differs:\n".format(prop) description += "property {} differs:\n".format(prop)
if prop not in olddiff["properties"]: if prop not in entity0_diff["properties"]:
description += "it does not exist in the " + label_old + ":\n" description += "it does not exist in the " + label_e0 + ":\n"
elif prop not in newdiff["properties"]: elif prop not in entity1_diff["properties"]:
description += "it does not exist in the " + label_new + ":\n" description += "it does not exist in the " + label_e1 + ":\n"
else: else:
description += label_old + ": {}\n".format( description += label_e0 + ": {}\n".format(
olddiff["properties"][prop]) entity0_diff["properties"][prop])
description += label_new + ": {}\n\n".format( description += label_e1 + ": {}\n\n".format(
newdiff["properties"][prop]) entity1_diff["properties"][prop])
if description != "": if description != "":
description = ("## Difference between the " + description = ("## Difference between the " +
label_old + label_e0 +
" and the " + " and the " +
label_new + label_e1 +
" of {}\n\n".format(name)) + description " of {}\n\n".format(name)) + description
return description return description
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment