fix(command-safety): make python -m arity entries reachable in classify_command#3588
Merged
Merged
Conversation
…fy_command The COMMAND_ARITY entries "python -m" and "python3 -m" could never match: classify_command strips flag tokens (those starting with -) before looking the prefix up, so "-m" is gone by the time the lookup runs. As a result `python -m http.server` collapsed to the bare `python` prefix, losing the module-level granularity those entries were meant to provide (and making `python -m http.server` indistinguishable from `python -m pip`). Key the entries on the bare interpreter instead, matching the upstream opencode port (`python: 2 // python -m venv env`). Arity 2 captures the module/script word that follows the stripped flag, so `python -m http.server` now classifies to `python http.server` and `python manage.py` to `python manage.py`.
|
Thanks @chatman-media for taking the time to contribute. This repository is observing a maintainer-managed PR intake gate in dry-run mode, so this pull request is staying open. This note helps maintainers prepare the allowlist before any enforcement is considered. Please read |
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.
The
COMMAND_ARITYentries("python -m", 3)and("python3 -m", 3)are dead — they can never match.classify_commandstrips flag tokens (anything starting with-) before doing the arity lookup, so-mis gone by the time the key is compared.python -m http.servertherefore collapses to the barepythonprefix, losing the module-level granularity those entries were meant to provide and makingpython -m http.serverindistinguishable frompython -m pip.Fix
Key the entries on the bare interpreter instead — matching the upstream opencode port these were ported from (
python: 2 // python -m venv env). Arity 2 captures the module/script word that follows the stripped flag:python -m http.serverpythonpython http.serverpython -m pip install xpythonpython pippython manage.py runserverpythonpython manage.pyTests
Added
classify_python_module_captures_module_wordandclassify_python_script_arity_2. Both fail onmain(left: "python") and pass with the fix. Fullcommand_safetysuite (57 tests) stays green.