Skip to content

_user_req_input ignores valid falsy values #213

Description

@daniel-montanari

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions