fix: pwsh autocompletion not returning command hints#1685
Draft
nrynmish wants to merge 3 commits intofastapi:masterfrom
Draft
fix: pwsh autocompletion not returning command hints#1685nrynmish wants to merge 3 commits intofastapi:masterfrom
nrynmish wants to merge 3 commits intofastapi:masterfrom
Conversation
svlandeg
reviewed
Apr 13, 2026
Member
svlandeg
left a comment
There was a problem hiding this comment.
Thanks for the PR! I'll put this in draft while the test suite fails, feel free to mark as ready when everything is green.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #266
What's the bug?
PowerShellComplete.get_completion_args()was slicingcwords[1:]to skip the interpreter, but$commandAst.ToString()in the PowerShell template includes both the interpreter (python) and the prog name (main.py) as the first two tokens.This meant
main.pywas leaking into the args passed to Click's completion resolver, which couldn't match it to any command and returned no completions — causing PowerShell to silently fall back to path-only completion.Changes
typer/_completion_classes.pycwords[1:]→cwords[2:]andcwords[1:-1]→cwords[2:-1]inPowerShellComplete.get_completion_args()to correctly skip both the interpreter and prog name tokens.typer/_completion_shared.py$Env:VAR = ""withRemove-Item Env:VARto fully unset environment variables after completion, preventing stale values from affecting repeated completions.Testing
Tested by mocking
_TYPER_COMPLETE_ARGSand_TYPER_COMPLETE_WORD_TO_COMPLETEenv vars and asserting correct args slicing before and after the fix. Also verified end-to-end withpwshon Linux.