Skip to content

fix: stop the help check at the -- end-of-options marker - #424

Merged
weibullguy merged 2 commits into
PyCQA:masterfrom
shashank11yadav:fix/help-check-after-double-dash
Dec 3, 2026
Merged

weibullguy merged 2 commits into
PyCQA:masterfrom
shashank11yadav:fix/help-check-after-double-dash

Conversation

@shashank11yadav

Copy link
Copy Markdown
Contributor

Fixes #423

The help pre-check in _main (src/docformatter/__main__.py) searched every command-line token for -h and --help, including the tokens after the -- end-of-options marker. Tokens after -- are file names, but a file or directory literally named -h given after -- was treated as the help flag: the usage text was printed and the function returned 0 before any file was read.

This change cuts the token list at the first -- before the help check runs. -h and --help before -- work as before.

The case that matters is a recursive check (--check and --recursive) whose path after -- is a directory named -h full of Python files. Before this change that run printed the usage text and returned exit code 0, so the check reported nothing and exited 0.

How it was tested:

  • A new test, test_help_flag_after_end_of_options_is_a_path in tests/test_docformatter.py, creates a directory named -h containing a file with a docstring that needs fixing, then runs the check with -- before -h. It expects exit code 3. The new test passes with the fix and fails without it (exit code 0 instead of 3).
  • The full test suite, uv run --no-sync python -m pytest -c pyproject.toml tests/: 819 passed, 3 skipped.
  • ruff check and pydocstyle on src and docs/source, black --check and isort --check-only on src and docs/source, docformatter --check on src/docformatter/__main__.py, and mypy on src/docformatter: all exited 0.
  • I did not run the pre-commit hooks (tox -e pre-commit). The linters and formatters were run directly on the paths above rather than through pre-commit.
  • The other Python versions in the CI matrix were not run locally.

The -h / --help pre-check in _main scanned every command-line token,
including the ones after "--". A path named -h passed after the marker
printed the usage text and exited 0 without formatting or checking
anything, so "docformatter --check --recursive -- -h" passed silently.

Cut the token list at the first "--" before looking for the help flags.
@weibullguy
weibullguy merged commit 5abcd83 into PyCQA:master Dec 3, 2026
7 checks passed
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.

fix: -h/--help after -- prints help instead of being treated as a file name

2 participants