exec-builtin: flag non-call references in preview mode - #28051
Open
CAOShurong wants to merge 1 commit into
Open
Conversation
`exec-builtin` (S102) only flagged direct calls to the builtin `exec`, while `suspicious-eval-usage` (S307) also flags references such as `map(eval, ...)` or `foo = eval` in preview mode. Extend the preview-mode reference detection in `suspicious_function` to cover `exec` so both rules behave consistently. Calls remain reported once via the existing call-site check; references are preview-gated behind the same `suspicious_function_reference` machinery used by S307. Fixes astral-sh#28011
|
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.
Summary
exec-builtin(S102) currently flags only direct calls to the builtinexec, while the parallel rulesuspicious-eval-usage(S307) also flags non-call references likemap(eval, ...)orfoo = evalin preview mode (behavior added in #15522/#15523). This makes the two rules inconsistent:This extends the existing preview-mode reference detection (
suspicious_function_reference) to coverexec, so both rules treat references consistently. The reference diagnostics are gated behind the same preview flag as S307's, so stable-mode output is unchanged.Calls are still reported exactly once via the existing call-site check (
exec_used); the new arm only matches non-call references to avoid duplicate diagnostics.Fixes #28011
Test Plan
flake8_bandit/S102.py:list(map(exec, ["hi"]))andfoo = exec(both flagged in preview), plus a shadowed localexec(not flagged).preview_rulestest case forExecBuiltin/S102.py; snapshot shows exactly the two added reference diagnostics vs. stable mode.cargo test -p ruff_linter --release --libgreen (2797 passed);cargo fmt --checkclean.