[flake8-pyi] Implement PYI062 (duplicate-literal-member) (#11269)

This commit is contained in:
Tushar Sadhwani 2024-05-07 23:58:06 +05:30 committed by GitHub
parent 1a392d34e1
commit 56b4c47d74
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 451 additions and 0 deletions

View file

@ -1350,6 +1350,15 @@ impl<'a> SemanticModel<'a> {
false
}
/// Return `true` if the model is in a nested literal expression (e.g., the inner `Literal` in
/// `Literal[Literal[int, str], float]`).
pub fn in_nested_literal(&self) -> bool {
// Ex) `Literal[Literal[int, str], float]`
self.current_expression_grandparent()
.and_then(Expr::as_subscript_expr)
.is_some_and(|parent| self.match_typing_expr(&parent.value, "Literal"))
}
/// Returns `true` if `left` and `right` are in the same branches of an `if`, `match`, or
/// `try` statement.
///