New rule in flake8-tidy-imports for banning specific function calls #16204
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
This commit introduces a new lint rule (TID254) that flags forbidden function calls, such as
os.system
andos.popen
, in alignment with a project’s banned functions configuration. Highlights include:BannedFunction
rule to detect and report banned function calls.banned_functions
) withinflake8_tidy_imports
.TID254.py
) and snapshot to verify detection.This was requested here: #9236 and I have encountered some use cases for this as well.
While this is not technically part of the
flake8-tidy-imports
module it seemed like the closest fit from the current set of them.n.b. I don't have a huge amount of rust experience, and this was implemented with significant assistance from llms so please let me know if anything looks off!
Test Plan
Tests were added modeled off of TID251 for banned APIs to cover a variety of cases as outlined in the test file.
I also verified this against another codebase with a release build of ruff and it seems to be working as expected.