Skip to content

tab completion for choices not work when specifying type #442

@function2-llx

Description

@function2-llx

🐛 Bug report

When specifying both choices and type in parser.add_argument, the tab completion for choices will not work.

To reproduce

Create a simple script named example.py with execute permission:

#! /bin/env python

from jsonargparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('x', type=str, choices=['a', 'b', 'c'])

args = parser.parse_args()

Open a shell, calling eval "`register-python-argcomplete example.py`", and type: ./example.py <TAB>.

Expected behavior

Showing the following content as if using the vanilla argparse package:

c       b   a  --                                                                                                                
--help  -h     -- show this help message and exit

Actual behavior

In zsh, nothing shows; in bash, the following content shows:

-h                                       --help                                    value not yet valid, expected type str

Environment

  • jsonargparse version: 4.27.1
  • Python version: 3.11.7
  • How jsonargparse was installed: pip install jsonargparse[signatures, omegaconf, argcomplete]
  • OS: Linux (Ubuntu 22.04)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions