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 1 year 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

FYI, in the future you don't need to close and open a new PR when you want to add new commits. You can just (sometimes, force) push to the same remote branch

seakrueger avatar Jul 13 '24 14:07 seakrueger

@seakrueger I know, but I didn't know if id find what was the introduced issue on time, so to prevent people wasting time taking a look I closed it and created a new one when ready. cheers

dardevelin avatar Jul 13 '24 16:07 dardevelin

I'm afraid this PR is now obsolete when #332 has been merged. If you disagree, feel free to reopen it.

yedpodtrzitko avatar Sep 09 '24 07:09 yedpodtrzitko