Skip to content

exec-builtin: flag non-call references in preview mode - #28051

Open
CAOShurong wants to merge 1 commit into
astral-sh:mainfrom
CAOShurong:fix/exec-builtin-references
Open

exec-builtin: flag non-call references in preview mode#28051
CAOShurong wants to merge 1 commit into
astral-sh:mainfrom
CAOShurong:fix/exec-builtin-references

Conversation

@CAOShurong

Copy link
Copy Markdown

Summary

exec-builtin (S102) currently flags only direct calls to the builtin exec, while the parallel rule suspicious-eval-usage (S307) also flags non-call references like map(eval, ...) or foo = eval in preview mode (behavior added in #15522/#15523). This makes the two rules inconsistent:

exec("hi")            # S102 fires
list(map(exec, []))   # nothing -- but map(eval, []) gets S307 in preview

This extends the existing preview-mode reference detection (suspicious_function_reference) to cover exec, 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

  • New fixture cases in flake8_bandit/S102.py: list(map(exec, ["hi"])) and foo = exec (both flagged in preview), plus a shadowed local exec (not flagged).
  • Added a preview_rules test case for ExecBuiltin/S102.py; snapshot shows exactly the two added reference diagnostics vs. stable mode.
  • cargo test -p ruff_linter --release --lib green (2797 passed); cargo fmt --check clean.

`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
@astral-sh-bot
astral-sh-bot Bot requested a review from ntBre August 25, 2026 21:37
@astral-sh-bot

astral-sh-bot Bot commented Aug 25, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

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.

exec-builtin should also warn on references to the exec function

1 participant