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

[bug] when choices is a set #155

Closed
Freed-Wu opened this issue Oct 26, 2023 · 1 comment
Closed

[bug] when choices is a set #155

Freed-Wu opened this issue Oct 26, 2023 · 1 comment
Assignees
Labels
duplicate Déjà lu invalid Doesn't seem right

Comments

@Freed-Wu
Copy link
Contributor

If we

    parser.add_argument(
        "--color",
        choices={"auto", "always", "never"},
        default="auto",
        help="when to display color",
    )

It is legal, because argparse only check choice in choices, and it will be faster than choices is a list.

However, shtab will:

        File "/tmp/pip-build-env-xrs7p_m9/overlay/lib/python3.11/site-packages/shtab/__init__.py", line 795, in __call__
          print(complete(parent or parser, values, preamble=preamble))
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-xrs7p_m9/overlay/lib/python3.11/site-packages/shtab/__init__.py", line 784, in complete
          return completer(
                 ^^^^^^^^^^
        File "/tmp/pip-build-env-xrs7p_m9/overlay/lib/python3.11/site-packages/shtab/__init__.py", line 506, in complete_zsh
          "cmd": prog, "arguments": [
                                    ^
        File "/tmp/pip-build-env-xrs7p_m9/overlay/lib/python3.11/site-packages/shtab/__init__.py", line 507, in <listcomp>
          format_optional(opt, parser)
        File "/tmp/pip-build-env-xrs7p_m9/overlay/lib/python3.11/site-packages/shtab/__init__.py", line 488, in format_optional
          (choice_type2fn[opt.choices[0].type] if isinstance(opt.choices[0], Choice) else
                                                             ~~~~~~~~~~~^^^
      TypeError: 'set' object is not subscriptable
Freed-Wu added a commit to termux/termux-language-server that referenced this issue Oct 26, 2023
Freed-Wu added a commit to termux/termux-language-server that referenced this issue Oct 26, 2023
@casperdcl
Copy link
Collaborator

Duplicate of #95 (comment)

According to https://docs.python.org/3/library/argparse.html#choices, choices must be a sequence. Sets are not sequences. isinstance(set(), typing.Sequence) == False.

@casperdcl casperdcl closed this as not planned Won't fix, can't repro, duplicate, stale Dec 1, 2023
@casperdcl casperdcl added duplicate Déjà lu invalid Doesn't seem right labels Dec 1, 2023
@casperdcl casperdcl self-assigned this Dec 1, 2023
Freed-Wu added a commit to termux/termux-language-server that referenced this issue Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Déjà lu invalid Doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants