Skip to content

Add type hints to the public parallel client API and a py.typed marker - #433

Open
DanShinde wants to merge 2 commits into
ParallelSSH:masterfrom
DanShinde:type-hints-public-api
Open

DanShinde wants to merge 2 commits into
ParallelSSH:masterfrom
DanShinde:type-hints-public-api

Conversation

@DanShinde

Copy link
Copy Markdown

First step for #370.

This adds type hints to the parts of the API most users touch, and ships a py.typed marker (PEP 561) so mypy and other type checkers pick them up:

  • pssh.clients.ParallelSSHClient (native) and pssh.clients.ssh.ParallelSSHClient: __init__, run_command, copy_file, copy_remote_file, scp_send, scp_recv
  • BaseParallelSSHClient: hosts, open_shell, run_shell_commands, join_shells, get_last_output, connect_auth, join, finished, copy_file
  • HostOutput (including stdout, stderr, exit_code), HostOutputBuffers, BufferData, HostConfig

Notes:

  • Uses from __future__ import annotations and typing.Optional/List etc., so it stays compatible with Python 3.8. No runtime behaviour changes.
  • py.typed is added to package_data and MANIFEST.in; I checked it ends up in the built wheel.
  • The native and ssh run_command / native copy_remote_file take an extra sudo / encoding argument compared to the base class, which mypy reports as an incompatible override. I left those signatures alone and added # type: ignore[override] on the three subclass methods, and left the base run_command / copy_remote_file unannotated.
  • Small typing-only cleanups that mypy flagged: explicit return None in HostOutput properties, HostOutput.stdout/stderr also return None when there are no buffers, {fully_qualified_command!r} in __repr__ (same output for bytes), and a finished stub on BaseSSHClient next to get_exit_status.

mypy is clean on the changed modules, flake8 is clean, unit tests pass, and the libssh2/libssh parallel integration tests give the same results as master in my environment. A quick downstream check now catches e.g. client.run_command(123) and exit_code being Optional[int].

If this direction looks good, I can follow up with the single clients (SSHClient) and the remaining modules.

Annotates ParallelSSHClient (native and ssh), BaseParallelSSHClient,
HostOutput and HostConfig, and ships a py.typed marker so type checkers
use the hints. First step for ParallelSSH#370.
@codecov

codecov Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 99.36%. Comparing base (6bfe5f9) to head (97fd417).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #433      +/-   ##
==========================================
- Coverage   99.47%   99.36%   -0.12%     
==========================================
  Files          18       18              
  Lines        1708     1720      +12     
==========================================
+ Hits         1699     1709      +10     
- Misses          9       11       +2     

β˜” View full report in Codecov by Harness.
πŸ“’ Have feedback on the report? Share it here.

πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@DanShinde

Copy link
Copy Markdown
Author

On the two red Codecov checks: the lines it reports as uncovered are the if TYPE_CHECKING: import blocks. Those imports exist only for type checkers and never run at runtime, so no test can cover them. Commit 97fd417 adds if TYPE_CHECKING: to exclude_lines in .coveragerc so coverage skips those blocks. If the Codecov status still shows the earlier numbers, it may not have been recalculated for that commit yet. The CircleCI test jobs pass. If you'd rather not change .coveragerc, I can drop that commit and mark the blocks with # pragma: no cover instead.

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