You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The reason will be displayed to describe this comment to others. Learn more.
I think it would make sense to return right here for all of these rules. The same argument about TYPE_CHECKING seems to apply to all of the rules that only check imports, and this would avoid all the separate checks and continues.
Thanks! I agree — since this check is import-only, it makes sense to early-return for TYPE_CHECKING blocks at the top level. I'll refactor accordingly and remove the per-rule continues.
Heads-up: the CI workflow is ending immediately with conclusion=action_required on this PR from a fork. Could a maintainer approve/enable the workflow run (or rerun CI) on their side? The local tests (cargo test -p ruff_linter flake8_bandit::) are passing.
Heads-up: the CI workflow is ending immediately with conclusion=action_required on this PR from a fork. Could a maintainer approve/enable the workflow run (or rerun CI) on their side? The local tests (cargo test -p ruff_linter flake8_bandit::) are passing.
Thanks, this is an intentional setting for first-time contributors. We'll notice and run CI, so you don't have to give us a heads-up.
ntBre
changed the title
flake8-bandit: skip S408/S409 inside TYPE_CHECKING blocks
[flake8-bandit] Allow suspicious imports in TYPE_CHECKING blocks (S401-S415)
Feb 24, 2026
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
previewRelated to preview mode featuresruleImplementing or modifying a lint rule
2 participants
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.
Fix false positives for S408/S409 when
xml.dom.minidomorxml.dom.pulldomare imported insideif TYPE_CHECKING:blocks.Imports inside TYPE_CHECKING are not executed at runtime, so they should not trigger these Bandit-based security rules.
Adds a dedicated fixture and snapshot test for the TYPE_CHECKING case.
Refs #14901