Skip to content

[pexpect] Fix return types of run(), runu() and spawn.wait() - #16826

Open
hemtilva wants to merge 2 commits into
python:mainfrom
hemtilva:pexpect-wait-run
Open

hemtilva wants to merge 2 commits into
python:mainfrom
hemtilva:pexpect-wait-run

Conversation

@hemtilva

Copy link
Copy Markdown
Contributor

Fixes #16825

  • run() gets overloads keyed on withexitstatus and encoding: bytes by default, str with an encoding, and tuple[..., int | None] with withexitstatus=True. A plain bool falls back to the union. runu() gets the same with str output.
  • The exit status is int | None, since it's None when the child is killed by a signal. spawn.wait() changes to int | None for the same reason.
  • events accepts string/bytes responses or callbacks, as described in run()'s docstring.
  • New @tests/test_cases/check_run.py. It has 11 errors against the current stubs and passes with this change (regr_test.py pexpect for linux and win32). mypy on stubs/pexpect is clean.

The overloads are verbose, since withexitstatus is positional, so each output type needs a Literal[False]/Literal[True]/bool variant. I'm happy to trim the bool fallbacks if you'd prefer.

I used Claude to help find this and write the change. The runtime behaviour was checked against pexpect 4.9.0 on Linux (WSL).

Copilot AI balanced review requested due to automatic review settings November 16, 2026 05:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

This branch has not been deployed

No deployments
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.

[pexpect] run()/runu() return types reject documented usage; wait() can return None

2 participants