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

_user_req_input ignores valid falsy values #213

Open
daniel-montanari opened this issue Aug 14, 2024 · 0 comments
Open

_user_req_input ignores valid falsy values #213

daniel-montanari opened this issue Aug 14, 2024 · 0 comments
Assignees

Comments

@daniel-montanari
Copy link
Collaborator

daniel-montanari commented Aug 14, 2024

The ui implementations of requesting user input have a flaw when returning results.
This is due to the validator functions returning a Union of validated input and False . The ui functions then blindly convert the result to a boolean and loop without feedback if a false value is received from the input validator. If a valid input converts to false, then the input is discarded.

I found this happening specifically with user_input_float as 0 or 0.0 are valid floats.

In cmd_line.py

    for _ in range(attempts):
        # This will change based on the interface
        print("\a")
        ret_val = input(msg)
        if target is None:
            q.put(ret_val)
            return
        ret_val = target(ret_val, **kwargs)
        if ret_val:
            q.put(("Result", ret_val))
            return

In ui_gui_qt.py

        for _ in range(attempts):
            # This will change based on the interface
            ret_val = self.gui_user_input(msg, None)
            if target is None or ret_val == "ABORT_FORCE":
                q.put(ret_val)
                return
            ret_val = target(ret_val, **kwargs)
            if ret_val:
                q.put(("Result", ret_val))
                return

example validator target

def _float_validate(entry):
    """Requires float entry"""
    try:
        return float(entry)
    except ValueError:
        user_info("Please enter a number")
        return False
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

No branches or pull requests

2 participants