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

improve code readability #72

Merged
merged 2 commits into from
Apr 27, 2024
Merged

Conversation

yedpodtrzitko
Copy link
Collaborator

Hi,
this PR aims to simplify some pieces of code to improve readability. Beside that there's a few tiny fixes for potential bugs (see my comments on given lines)

clear()
return -1
# Selection ====================================================
elif int(com[0]) > 0 and int(com[0]) <= len(choices):
elif com_name.isdigit() and 0 < int(com_name) <= len(choices):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here I added condition .isdigit(), otherwise it could end up with ValueError when calling int() on non-numeric string.

@@ -2625,14 +2627,14 @@ def scr_edit_entry_text(self, entry_index, field_index, allow_newlines=True, cle
self.lib.update_entry_field(
entry_index, field_index, new_content.rstrip('\n').rstrip('\r'), 'replace')

def scr_list_tags(self, query: str = '', tag_ids: list[int] = [], clear_scr=True) -> None:
def scr_list_tags(self, query: str = '', tag_ids: list[int] = None, clear_scr=True) -> None:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the empty list as a default parameter isnt intentional, then it might be causing some issues, see https://docs.python-guide.org/writing/gotchas/#mutable-default-arguments

@@ -4601,7 +4601,7 @@ def expand_collation(self, collation_entries: list[tuple[int, int]]):
for x in collation_entries])
# self.update_thumbs()

def get_frame_contents(self, index=0, query=str):
def get_frame_contents(self, index=0, query: str = None):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume query=str was supposed to be query:str, right? And since it's after a parameter with a default value, it needs some default value as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that looks to be like the original intention. Surprised my linter didn't pick that up...

Copy link
Member

@CyanVoxel CyanVoxel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't believe I didn't know about the get() method until now...
Overall looks great! Thanks for the cleanup!

@CyanVoxel CyanVoxel merged commit 2110592 into TagStudioDev:main Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants