Skip to content

Conversation

pmhahn
Copy link

@pmhahn pmhahn commented Oct 13, 2025

I found your project while looking for how to get bash completion automatically from ArgumentParser. Sadly Ubuntu 24.04 ships a broken version, so I had a look at your GitHub repository. Great work. Sadly there are several pending open issues and other PRs, so I hope you will find some time to work on this again soon.

  1. While looking at the code I noticed that type-annotations were incomplete. As I'm a huge fan of type-annotated code myself, I took my time to add it to all functions.1
  2. I upgraded the old annotations to use list[…] instead of typing.Lits[…] and such.
  3. As usual mypy found some minor issues, which I also fixed. See individual commits at the front.
  4. While looking at the generated code shellcheck found many issues, mostly related to missing quotes. I fixed the code, which generates those. See individual commits in the middle.
  5. __init__.py is quiet large and contains mixed Python/shell code. Maybe it might be a good idea to move the shell-code to separate files; see last commit.

If you prefer I can send you smaller pull requests only doing one thing at a time. But before I spend more time on this, I'd like to get your feedback if such changes are preferred or not.

Footnotes

  1. For complete type annotations typing.Protocol from Python 3.8 (EoL last year) is needed. Therefor I bumped the minimum supported version to 3.8 not that 3.14 got released. By using from __future__ import annotations and if TYPE_CHECKING: the code still runs with 3.8. Using from collections.abc import … instead of from typing import … works only since Python 3.9 (EoL this month). Raising the minimum version to 3.9 thus might be preferred.

Philipp Hahn added 20 commits October 10, 2025 18:05
E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks

Signed-off-by: Philipp Hahn <[email protected]>
> shtab/__main__.py:8: error: "main" does not return a value (it only ever returns None)

Signed-off-by: Philipp Hahn <[email protected]>
ArgumentParser._get_optional_actions() will always return instances of
`Action` and never `SUPPRESS`, which is a `str`.

Signed-off-by: Philipp Hahn <[email protected]>
Also handle input redirection.
Also handle other file descriptors than STDOUT and STDERR.
No backslash at the end of the line is required after && and ||.

Signed-off-by: Philipp Hahn <[email protected]>
Declare some variables as integers, so `var+=1` can be used.

Signed-off-by: Philipp Hahn <[email protected]>
SC2199 (error): Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @).

Signed-off-by: Philipp Hahn <[email protected]>
Required for:
- `typing.Protocol`
- walrus operator

Using `collections.abc` instead of `typing` requires 3.9 for
type-checking only!

Signed-off-by: Philipp Hahn <[email protected]>
typing.List[…] -> list[…]
typing.Dict[…] -> dict[…]
typing.Union[…] -> … | …
typing.Optional[…] -> … | None

Signed-off-by: Philipp Hahn <[email protected]>
Signed-off-by: Philipp Hahn <[email protected]>
Signed-off-by: Philipp Hahn <[email protected]>
Also get rid of `cases` changing type from `list[str]` to `str`.

Signed-off-by: Philipp Hahn <[email protected]>
Use list-comprehension instead of sum(); it's easier to grasp and
faster.

Signed-off-by: Philipp Hahn <[email protected]>
Signed-off-by: Philipp Hahn <[email protected]>
Drop Python 3.7 support as the Walrus-operator only available since 3.8.

Signed-off-by: Philipp Hahn <[email protected]>
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

Successfully merging this pull request may close these issues.

1 participant