TagStudio icon indicating copy to clipboard operation
TagStudio copied to clipboard

[chore]Make get_field_attr safe and improve control flow in ts_core.py

Open dardevelin opened this issue 7 months ago • 2 comments

Refactor get_field_attr in library.py and improve control flow in ts_core.py

Changes:

1. Refactor get_field_attr in library.py:

  • Ensure safety using list slicing to avoid IndexError.
  • Use any to determine if there is a value before using it.
  • Use .get() for dictionary access to handle default cases and prevent KeyError.

2. Improve control flow in ts_core.py:

  • Remove nesting by exiting early in match_conditions.
  • Eliminate the need for try-catch blocks for better readability and control flow.

Additional Fix:

  • Included fix for non-merged pull request #318.

Note:

  • Kept existing_fields case unchanged due to add_field_to_entry's procedural nature.

dardevelin avatar Jul 13 '24 03:07 dardevelin