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

Mutually exclusive option groups behave strangely when given default values #901

Open
lcdevans opened this issue Feb 7, 2024 · 0 comments

Comments

@lcdevans
Copy link

lcdevans commented Feb 7, 2024

  • [Windows 10] OS
  • [3.11.5 ] Python Version
  • [ 1.0.8.1] Gooey Version
  • add_mutually_exclusive_group is buggy when options are given default values
    • Behaviour is difficult to describe, but it seems like default options aren't correctly added if left at their default value. Try to run this code and you'll see what I mean.
    • I would have expected the code to work with args.first ==1 when first is selected, and likewise for args.second. As it is, this just crashes and says neither are selected.

Minimal reproducer:

@Gooey(program_name="Minimal Reproducer")
def main():
    parser = GooeyParser()

    mutex = parser.add_mutually_exclusive_group(
        required=True, gooey_options={"initial_selection": 0}
    )
    mutex.add_argument(
        "--first",
        type=int,
        default=1,
        help="First mutex argument."
    )
    mutex.add_argument(
        "--second",
        type=int,
        default=2,
        help=f"Second mutex argument.",
    )

    args = parser.parse_args()

    if hasattr(args, "first") and args.first is not None:
        print(f"first: {args.first}")
    elif hasattr(args, "second") and args.second is not None:
        print(f"second: {args.second}")


if __name__ == "__main__":
    main()

For my own usage I'm able to just enforce the behaviour I want by writing a little code, but this did not work the way I would have expected.

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

1 participant