You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When defining arguments with using pathlib.Path, such as p.add_argument("-s", "--src", type=Path) on an ArgumentParser instance, the autocomplete mechanism should understand the type and emit an autocomplete that is compatible with both a file or directory.
Context/Comments
Path is commonly used and communicates the fundamental intent that the argument is PathLike.
Currently, when defining File/Dir, the user needs to add .complete (e.g., p.add_argument("-s", "--src", type=Path).complete = shtab.FILE). This is easy to forget and it's not a particulary obvious interface to Action. Also, your text editing won't be able to help or assist you. For example, a simple mistyping of .completion = shtab.FILE can create confusion.
Adding .complete doesn't play well with static analysis tools such as mypy in strict mode. Using .complete = ... will yield an error (example.py:29: error: "Action" has no attribute "complete" [attr-defined]
Using .complete = shtab.FILE model requires an explicit dependency on shtab. It's useful to make shtab an optional dependency with a try/catch ImportError and use shtab.add_argument_to(p) when defining a get_parser() function.
If you don't explicitly add .complete style for a Path, then you loose any "default" autocomplete mechanics of file/dir behavior in the shell.
Requirements:
pathlib.Path, such asp.add_argument("-s", "--src", type=Path)on anArgumentParserinstance, the autocomplete mechanism should understand the type and emit an autocomplete that is compatible with both a file or directory.Context/Comments
.complete(e.g.,p.add_argument("-s", "--src", type=Path).complete = shtab.FILE). This is easy to forget and it's not a particulary obvious interface toAction. Also, your text editing won't be able to help or assist you. For example, a simple mistyping of.completion = shtab.FILEcan create confusion..completedoesn't play well with static analysis tools such asmypyin strict mode. Using.complete = ...will yield an error (example.py:29: error: "Action" has no attribute "complete" [attr-defined].complete = shtab.FILEmodel requires an explicit dependency onshtab. It's useful to make shtab an optional dependency with a try/catch ImportError and useshtab.add_argument_to(p)when defining aget_parser()function..completestyle for a Path, then you loose any "default" autocomplete mechanics of file/dir behavior in the shell.