mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:16 +00:00
Avoid PEP 604 isinstance errors for starred tuples (#3527)
This commit is contained in:
parent
58353a4bf4
commit
2545869797
2 changed files with 11 additions and 0 deletions
|
@ -6,3 +6,4 @@ issubclass("yes", int) # OK
|
||||||
isinstance(1, int | float) # OK
|
isinstance(1, int | float) # OK
|
||||||
issubclass("yes", int | str) # OK
|
issubclass("yes", int | str) # OK
|
||||||
isinstance(1, ()) # OK
|
isinstance(1, ()) # OK
|
||||||
|
isinstance(1, (int, *(str, bytes))) # OK
|
||||||
|
|
|
@ -79,9 +79,19 @@ pub fn use_pep604_isinstance(checker: &mut Checker, expr: &Expr, func: &Expr, ar
|
||||||
};
|
};
|
||||||
if let Some(types) = args.get(1) {
|
if let Some(types) = args.get(1) {
|
||||||
if let ExprKind::Tuple { elts, .. } = &types.node {
|
if let ExprKind::Tuple { elts, .. } = &types.node {
|
||||||
|
// Ex) `()`
|
||||||
if elts.is_empty() {
|
if elts.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ex) `(*args,)`
|
||||||
|
if elts
|
||||||
|
.iter()
|
||||||
|
.any(|elt| matches!(elt.node, ExprKind::Starred { .. }))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let mut diagnostic =
|
let mut diagnostic =
|
||||||
Diagnostic::new(IsinstanceWithTuple { kind }, Range::from(expr));
|
Diagnostic::new(IsinstanceWithTuple { kind }, Range::from(expr));
|
||||||
if checker.patch(diagnostic.kind.rule()) {
|
if checker.patch(diagnostic.kind.rule()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue