-
-
Notifications
You must be signed in to change notification settings - Fork 59
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
🐛 Bug report
Currently, the action.complete
for shtab
is FILE
only when it is ActionConfigFile
or Pathlike
for ActionTypeHint
, however, these doesn't cover the action of _ActionConfigLoad
.
jsonargparse/jsonargparse/_completions.py
Lines 144 to 162 in f5f2422
complete = None | |
if isinstance(action, ActionConfigFile): | |
complete = shtab.FILE | |
elif isinstance(action, ActionTypeHint): | |
typehint = action._typehint | |
if get_typehint_origin(typehint) == Union: | |
subtypes = [s for s in typehint.__args__ if s not in {NoneType, str, dict, list, tuple, bytes}] | |
if len(subtypes) == 1: | |
typehint = subtypes[0] | |
if is_subclass(typehint, Path): | |
if "f" in typehint._mode: | |
complete = shtab.FILE | |
elif "d" in typehint._mode: | |
complete = shtab.DIRECTORY | |
elif is_subclass(typehint, os.PathLike): | |
complete = shtab.FILE | |
if complete: | |
action.complete = complete | |
return |
To reproduce
Simple Example
# cli.py
from jsonargparse import ArgumentParser
from calendar import Calendar
class MyClass:
def __init__(self, calendar: Calendar):
self.calendar = calendar
parser = ArgumentParser()
parser.add_class_arguments(MyClass, "myclass", sub_configs=True)
cfg = parser.parse_args()
λ python cli.py --print_shtab=zsh
...
"--myclass[Path to a configuration file.]:myclass:"
...
Expected:
λ python cli.py --print_shtab=zsh
...
"--myclass[Path to a configuration file.]:myclass:_files"
...
since the following command work:
python cli.py --myclass test.yaml
with test.yaml
:
calendar:
class_path: calendar.Calendar
init_args:
firstweekday: 1
Environment
- jsonargparse version: 4.32.0
- Python version: 3.12
- How jsonargparse was installed: pip
- OS: Ubuntu 22.04
mauvilsa
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working