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

gui: Early exit from functions or loops #4916

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

echoix
Copy link
Member

@echoix echoix commented Jan 4, 2025

Analogous to #4910, but for files in gui/.

I verified all the changes when committing them to make sure they are equivalent and that they kept the comments. The places I was unsure I reverted them, so these are the ones that make sense

echoix added 2 commits January 4, 2025 14:14
Flattens nested conditionals and moves error messages or returns near the top
Flattens nested conditionals and moves error messages near the top
@github-actions github-actions bot added GUI wxGUI related Python Related code is in Python labels Jan 4, 2025
@echoix echoix requested a review from ninsbl January 15, 2025 23:37
@echoix echoix requested a review from petrasovaa January 16, 2025 17:18
Comment on lines 1701 to 1703
(self.GCPcount >= 3 or self.gr_order != 1)
and (self.GCPcount >= 6 or self.gr_order != 2)
and (self.GCPcount >= 10 or self.gr_order != 3)
Copy link
Contributor

Choose a reason for hiding this comment

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

This may be correct, but it's completely unreadable. Maybe evaluate these separately before?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll get to it next time I can :)

Copy link
Member Author

@echoix echoix Feb 1, 2025

Choose a reason for hiding this comment

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

Ok, I couldn't do better, even using not before wasn't pretty enough, so I partially reverted. However, by more closely analyzing it (plus type checking), that function could be returning None or a bool. I think that the intent of that (repeated) function, when reading the usages, is to return a bool. That means that the returns False should have been outside the if msg:. So I did that, so now it can't return None, only True or False.

There's another possible hole in this logic, as it means that if we have gr_order of 4, 5, 6 or more, we need 0 or more points to return True. In fact, the property self.GCPcount could be anything (negative, None, a string, etc), as it is unchecked if self.gr_order is not 1, 2 or 3.

gui/wxpython/image2target/ii2t_manager.py Outdated Show resolved Hide resolved
gui/wxpython/photo2image/ip2i_manager.py Outdated Show resolved Hide resolved
@arohanajit

This comment was marked as off-topic.

@echoix

This comment was marked as off-topic.

@echoix echoix requested a review from petrasovaa February 1, 2025 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GUI wxGUI related Python Related code is in Python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants