[pycodestyle] Exempt pytest.importorskip() calls (E402) (#14474)
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Blocked by required conditions
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz (push) Blocked by required conditions
CI / Fuzz the parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions

## Summary

Resolves #13537.

## Test Plan

`cargo nextest run` and `cargo insta test`.
This commit is contained in:
InSync 2024-11-20 10:08:15 +07:00 committed by GitHub
parent 6a4d207db7
commit b9c53a74f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 41 additions and 3 deletions

View file

@ -102,3 +102,24 @@ pub fn is_matplotlib_activation(stmt: &Stmt, semantic: &SemanticModel) -> bool {
.resolve_qualified_name(func.as_ref())
.is_some_and(|qualified_name| matches!(qualified_name.segments(), ["matplotlib", "use"]))
}
/// Returns `true` if a [`Stmt`] is a `pytest.importorskip()` call, as in:
/// ```python
/// import pytest
///
/// pytest.importorskip("foo.bar")
/// ```
pub fn is_pytest_importorskip(stmt: &Stmt, semantic: &SemanticModel) -> bool {
let Stmt::Expr(ast::StmtExpr { value, .. }) = stmt else {
return false;
};
let Expr::Call(ast::ExprCall { func, .. }) = value.as_ref() else {
return false;
};
semantic
.resolve_qualified_name(func.as_ref())
.is_some_and(|qualified_name| {
matches!(qualified_name.segments(), ["pytest", "importorskip"])
})
}