Skip to content

Commit

Permalink
implement review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>
  • Loading branch information
meretp committed May 16, 2023
1 parent 000a9db commit cb680cc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/spdx_tools/common/typing/dataclass_with_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ def set_field_with_better_error_message(self, value: field_type):

def simplify_error_message_for_union(error_message: str) -> str:
# The error message from typeguard is more verbose than we need, so we simplify the message
# to provide the user with a compacter error message.
# to provide the user with a more compact error message.
types_in_union = re.compile(r"\n\s*(.*?):", re.UNICODE)
list_of_types = re.findall(types_in_union, error_message)
text_to_replace = error_message.split("did not match any element in the union:")[-1]
error_message = error_message.replace(text_to_replace, " " + str(list_of_types))
error_message = error_message.replace(text_to_replace, " [" + ", ".join(list_of_types) + "]")
return error_message

return set_field_with_better_error_message
Expand Down
6 changes: 3 additions & 3 deletions tests/spdx/parser/jsonlikedict/test_error_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ def test_error_message():
'Error while constructing Package: [\'SetterError Package: argument "name" '
"(None) is not an instance of str: None', 'SetterError Package: argument "
'"download_location" (int) did not match any element in the union: '
"[\\'str\\', \\'spdx_tools.spdx.model.spdx_no_assertion.SpdxNoAssertion\\', "
"\\'spdx_tools.spdx.model.spdx_none.SpdxNone\\']: 5', 'SetterError Package: "
"[str, spdx_tools.spdx.model.spdx_no_assertion.SpdxNoAssertion, "
"spdx_tools.spdx.model.spdx_none.SpdxNone]: 5', 'SetterError Package: "
'argument "file_name" (int) did not match any element in the union: '
"[\\'str\\', \\'NoneType\\']: 10', 'SetterError Package: item 1 of argument "
"[str, NoneType]: 10', 'SetterError Package: item 1 of argument "
"\"attribution_texts\" (list) is not an instance of str: [\\'text\\', 5, "
"{\\'test\\': \\'data\\'}]']"
],
Expand Down

0 comments on commit cb680cc

Please sign in to comment.