Repository navigation
Compare Bash version components numerically in the completion gate - #1983
Open
HyperionBurn wants to merge 1 commit into
Open
HyperionBurn wants to merge 1 commit into
HyperionBurn wants to merge 1 commit into
Conversation
BashComplete._check_version() gates shell completion on Bash being at least 4.4, but it compared the major and minor components as strings. Lexicographic ordering places "10" before "4", so any Bash whose major or minor component reaches 10 is reported as older than 4.4 and completion is incorrectly disabled. Parse the components as integers instead.
This branch has not been deployed
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.
What is broken
BashComplete._check_version()intyper/_completion_classes.pydecides whether to tell the user that Bash shell completion is unavailable. Bash is supported from 4.4 onwards, so the gate should report "too old" when the detected version is below 4.4.The check parses the version and then compares the two components as strings:
match.groups()returns text, so both comparisons are lexicographic. In Python"10" < "4"isTrue, because the character1sorts before4. Any Bash whose major or minor component reaches 10 is therefore reported as older than 4.4, and completion is switched off for a Bash that supports it perfectly well.I found this by reading the completion code; there is no tracking issue for it, and I checked the open and recently closed issue/PR lists for
BASH_VERSION/_check_version/ bash version gating to make sure it is not already covered.Reproduction
Script that fakes the detected
BASH_VERSIONand reports whether typer printed the "not supported" warning:Output on current
master:4.9.0is accepted but4.10.0is rejected. The version is going backwards.Test
tests/test_completion/test_completion_bash_version.pycovers the boundary in both directions: versions genuinely below 4.4 still warn, the 4.4/4.5/4.9/5.x cases still pass, and two-digit components are accepted.Failing before the fix:
(
5.10.0already passed, because only themajor == 4branch does a minor comparison, so only the four cases that reach a two-digitmajoror a two-digitminoron the 4.x line failed.)After the fix:
and the reproduction now reads:
The change
I also added the parentheses around
major == 4 and minor < 4, which was previously relying onandbinding tighter thanor. That is not a behaviour change, it just makes the precedence explicit now that the operands are integers.Full suite
Run locally on Windows with Python 3.14.6:
Baseline on unmodified
masterwas1478 passed, 21 skipped, 2 xfailed; the 14 extra tests are the new ones.Project CI on this branch is green as well, including the full platform matrix and the
pre-commitjob (which runsruff check,ruff format,mypy typerandty check typer):What I did not verify
Being explicit about the limits of the evidence:
shutil.whichandsubprocess.run, so it exercises the version gate only. I did not install a real Bash and did not verify that completion output is correct under an actual shell. Running the suite on a Linux/macOS CI runner does not exercise this either, since every job has its own Bash 5.x.mypy typerin my own virtualenv reported 6 errors in vendored click files I did not touch. Those did not reproduce in the project'spre-commitjob, which is the authoritative result; I mention it only so the discrepancy is on the record.test-cpython-nightlyworkflow, which this branch does not trigger.