Closed
Conversation
inikolaev
commented
May 14, 2023
inikolaev
commented
May 14, 2023
Comment on lines
+15
to
+17
| #[test_case(Rule::SyncHttpCallInAsyncFunction, Path::new("ASYNC100.py"); "ASYNC100")] | ||
| #[test_case(Rule::BlockingSyncCallInAsyncFunction, Path::new("ASYNC101.py"); "ASYNC101")] | ||
| #[test_case(Rule::SyncProcessCallInAsyncFunction, Path::new("ASYNC102.py"); "ASYNC102")] |
Author
There was a problem hiding this comment.
Not really sure if 3 different test cases are really necessary, I just followed other plugins. A single test case that tests all of them would work as well - all examples are functions with 1-2 lines.
inikolaev
commented
May 14, 2023
Comment on lines
+56
to
+89
| const HTTP_PACKAGES: [&str; 2] = ["httpx", "requests"]; | ||
| const HTTP_METHODS: [&str; 9] = ["get", "options", "head", "post", "put", "patch", "delete", "request", "send"]; | ||
| const TIME_METHODS: [&str; 1] = ["sleep"]; | ||
| const SUBPROCESS_METHODS: [&str; 7] = [ | ||
| "run", | ||
| "Popen", | ||
| // deprecated methods | ||
| "call", | ||
| "check_call", | ||
| "check_output", | ||
| "getoutput", | ||
| "getstatusoutput", | ||
| ]; | ||
| const OS_PROCESS_METHODS: [&str; 12] = [ | ||
| "popen", | ||
| "posix_spawn", | ||
| "posix_spawnp", | ||
| "spawnl", | ||
| "spawnle", | ||
| "spawnlp", | ||
| "spawnlpe", | ||
| "spawnv", | ||
| "spawnve", | ||
| "spawnvp", | ||
| "spawnvpe", | ||
| "system", | ||
| ]; | ||
| const OS_WAIT_METHODS: [&str; 5] = [ | ||
| "wait", | ||
| "wait3", | ||
| "wait4", | ||
| "waitid", | ||
| "waitpid", | ||
| ]; |
Author
There was a problem hiding this comment.
Copied from the original plugin
inikolaev
commented
May 14, 2023
Comment on lines
+93
to
+127
| if let StmtKind::Expr(ast::StmtExpr { value }) = &stmt.node { | ||
| if let ExprKind::Call(ast::ExprCall { func, .. }) = &value.node { | ||
| if let ExprKind::Name(ast::ExprName { id, .. }) = &func.node { | ||
| if "open" == id.as_str() { | ||
| let diagnostic = Diagnostic::new(BlockingSyncCallInAsyncFunction, stmt.range()); | ||
| checker.diagnostics.push(diagnostic); | ||
| } | ||
| } else if let ExprKind::Attribute(ast::ExprAttribute { value, attr, .. }) = &func.node { | ||
| if let ExprKind::Name(ast::ExprName { id, .. }) = &value.node { | ||
| let module = id.as_str(); | ||
| let method = attr.as_str(); | ||
| let range = stmt.range(); | ||
|
|
||
| if HTTP_PACKAGES.contains(&module) && HTTP_METHODS.contains(&method) { | ||
| let diagnostic = Diagnostic::new(SyncHttpCallInAsyncFunction, range); | ||
| checker.diagnostics.push(diagnostic); | ||
| } else if "time" == module && TIME_METHODS.contains(&method) { | ||
| let diagnostic = Diagnostic::new(BlockingSyncCallInAsyncFunction, range); | ||
| checker.diagnostics.push(diagnostic); | ||
| } else if "subprocess" == module && SUBPROCESS_METHODS.contains(&method) { | ||
| let diagnostic = Diagnostic::new(BlockingSyncCallInAsyncFunction, range); | ||
| checker.diagnostics.push(diagnostic); | ||
| } else if "os" == module { | ||
| if OS_WAIT_METHODS.contains(&method) { | ||
| let diagnostic = Diagnostic::new(BlockingSyncCallInAsyncFunction, range); | ||
| checker.diagnostics.push(diagnostic); | ||
| } else if OS_PROCESS_METHODS.contains(&method) { | ||
| let diagnostic = Diagnostic::new(SyncProcessCallInAsyncFunction, range); | ||
| checker.diagnostics.push(diagnostic); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
Author
There was a problem hiding this comment.
Quite straightforward implementation, happy to hear any feedback
Closed
Co-authored-by: Jonathan Plasse <13716151+JonathanPlasse@users.noreply.github.com>
3fee8ee to
40ea0a2
Compare
|
Looks like #4432 was submitted simultaneously? |
Contributor
PR Check ResultsBenchmarkLinuxWindows |
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.
Added implementation of flake8-async plugin and copied all the tests from it into
ruff.TODOs: