Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix variable access before assignment error #13

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions zs_yaml/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ def yaml_to_bin(yaml_input_path, bin_output_path):
yaml_input_path (str): Path to the input YAML file.
bin_output_path (str): Path to the output binary file.
"""
temp_json_path = None
try:
zserio_object, temp_json_path, _ = _yaml_to_zserio_object(yaml_input_path)
zserio.serialize_to_file(zserio_object, bin_output_path)
finally:
os.remove(temp_json_path)
if temp_json_path is not None:
os.remove(temp_json_path)

def yaml_to_pyobj(yaml_input_path):
"""
Expand All @@ -78,11 +80,13 @@ def yaml_to_pyobj(yaml_input_path):
Returns:
object: The deserialized Python object.
"""
temp_json_path = None
try:
zserio_object, temp_json_path, _ = _yaml_to_zserio_object(yaml_input_path)
return zserio_object
finally:
os.remove(temp_json_path)
if temp_json_path is not None:
os.remove(temp_json_path)

def yaml_to_yaml(yaml_input_path, yaml_output_path=None):
"""
Expand Down Expand Up @@ -177,4 +181,4 @@ def bin_to_yaml(bin_input_path, yaml_output_path):
final_data.update(data)

with open(yaml_output_path, 'w') as yaml_file:
yaml.safe_dump(final_data, yaml_file, default_flow_style=False, sort_keys=False)
yaml.safe_dump(final_data, yaml_file, default_flow_style=False, sort_keys=False)
Loading