From fbe3ef83aad9f2159184b8bdf1166589f15cc56e Mon Sep 17 00:00:00 2001 From: KV Date: Mon, 10 Jun 2024 21:40:44 +0200 Subject: [PATCH 1/2] Explain unexpeced top-level type (#383) Might help in reported issues like #342 --- src/wireviz/wireviz.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/wireviz/wireviz.py b/src/wireviz/wireviz.py index db692419..c0933ad3 100755 --- a/src/wireviz/wireviz.py +++ b/src/wireviz/wireviz.py @@ -86,6 +86,9 @@ def parse( raise Exception("No output formats or return types specified") yaml_data, yaml_file = _get_yaml_data_and_path(inp) + assert isinstance( + yaml_data, dict + ), f"Expected a dict as top-level YAML input, but got: {type(yaml_data)}" if output_formats: # need to write data to file, determine output directory and filename output_dir = _get_output_dir(yaml_file, output_dir) From 9f80e739c22daf7831fb5def9e801170bbfcbced Mon Sep 17 00:00:00 2001 From: kvid Date: Wed, 12 Jun 2024 22:49:09 +0200 Subject: [PATCH 2/2] Update src/wireviz/wireviz.py Raising TypeError is better than assert. (Black reformatted) Co-authored-by: Andreas Motl --- src/wireviz/wireviz.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/wireviz/wireviz.py b/src/wireviz/wireviz.py index c0933ad3..b7af0191 100755 --- a/src/wireviz/wireviz.py +++ b/src/wireviz/wireviz.py @@ -86,9 +86,10 @@ def parse( raise Exception("No output formats or return types specified") yaml_data, yaml_file = _get_yaml_data_and_path(inp) - assert isinstance( - yaml_data, dict - ), f"Expected a dict as top-level YAML input, but got: {type(yaml_data)}" + if not isinstance(yaml_data, dict): + raise TypeError( + f"Expected a dict as top-level YAML input, but got: {type(yaml_data)}" + ) if output_formats: # need to write data to file, determine output directory and filename output_dir = _get_output_dir(yaml_file, output_dir)