mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 21:35:58 +00:00
Fix various panicks when linting black/src (#13033)
This commit is contained in:
parent
0c98b5949c
commit
a35cdbb275
2 changed files with 39 additions and 20 deletions
|
@ -226,16 +226,25 @@ impl<'db> Type<'db> {
|
||||||
pub fn member(&self, db: &'db dyn Db, name: &Name) -> Type<'db> {
|
pub fn member(&self, db: &'db dyn Db, name: &Name) -> Type<'db> {
|
||||||
match self {
|
match self {
|
||||||
Type::Any => Type::Any,
|
Type::Any => Type::Any,
|
||||||
Type::Never => todo!("attribute lookup on Never type"),
|
Type::Never => {
|
||||||
|
// TODO: attribute lookup on Never type
|
||||||
|
Type::Unknown
|
||||||
|
}
|
||||||
Type::Unknown => Type::Unknown,
|
Type::Unknown => Type::Unknown,
|
||||||
Type::Unbound => Type::Unbound,
|
Type::Unbound => Type::Unbound,
|
||||||
Type::None => todo!("attribute lookup on None type"),
|
Type::None => {
|
||||||
Type::Function(_) => todo!("attribute lookup on Function type"),
|
// TODO: attribute lookup on None type
|
||||||
|
Type::Unknown
|
||||||
|
}
|
||||||
|
Type::Function(_) => {
|
||||||
|
// TODO: attribute lookup on function type
|
||||||
|
Type::Unknown
|
||||||
|
}
|
||||||
Type::Module(file) => global_symbol_ty_by_name(db, *file, name),
|
Type::Module(file) => global_symbol_ty_by_name(db, *file, name),
|
||||||
Type::Class(class) => class.class_member(db, name),
|
Type::Class(class) => class.class_member(db, name),
|
||||||
Type::Instance(_) => {
|
Type::Instance(_) => {
|
||||||
// TODO MRO? get_own_instance_member, get_instance_member
|
// TODO MRO? get_own_instance_member, get_instance_member
|
||||||
todo!("attribute lookup on Instance type")
|
Type::Unknown
|
||||||
}
|
}
|
||||||
Type::Union(union) => union
|
Type::Union(union) => union
|
||||||
.elements(db)
|
.elements(db)
|
||||||
|
@ -247,7 +256,7 @@ impl<'db> Type<'db> {
|
||||||
Type::Intersection(_) => {
|
Type::Intersection(_) => {
|
||||||
// TODO perform the get_member on each type in the intersection
|
// TODO perform the get_member on each type in the intersection
|
||||||
// TODO return the intersection of those results
|
// TODO return the intersection of those results
|
||||||
todo!("attribute lookup on Intersection type")
|
Type::Unknown
|
||||||
}
|
}
|
||||||
Type::IntLiteral(_) => {
|
Type::IntLiteral(_) => {
|
||||||
// TODO raise error
|
// TODO raise error
|
||||||
|
|
|
@ -1159,21 +1159,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||||
flags: _,
|
flags: _,
|
||||||
} = fstring;
|
} = fstring;
|
||||||
for element in elements {
|
for element in elements {
|
||||||
match element {
|
self.infer_fstring_element(element);
|
||||||
ast::FStringElement::Literal(_) => {
|
|
||||||
// TODO string literal type
|
|
||||||
}
|
|
||||||
ast::FStringElement::Expression(expr_element) => {
|
|
||||||
let ast::FStringExpressionElement {
|
|
||||||
range: _,
|
|
||||||
expression,
|
|
||||||
debug_text: _,
|
|
||||||
conversion: _,
|
|
||||||
format_spec: _,
|
|
||||||
} = expr_element;
|
|
||||||
self.infer_expression(expression);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1183,6 +1169,30 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||||
Type::Unknown
|
Type::Unknown
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn infer_fstring_element(&mut self, element: &ast::FStringElement) {
|
||||||
|
match element {
|
||||||
|
ast::FStringElement::Literal(_) => {
|
||||||
|
// TODO string literal type
|
||||||
|
}
|
||||||
|
ast::FStringElement::Expression(expr_element) => {
|
||||||
|
let ast::FStringExpressionElement {
|
||||||
|
range: _,
|
||||||
|
expression,
|
||||||
|
debug_text: _,
|
||||||
|
conversion: _,
|
||||||
|
format_spec,
|
||||||
|
} = expr_element;
|
||||||
|
self.infer_expression(expression);
|
||||||
|
|
||||||
|
if let Some(format_spec) = format_spec {
|
||||||
|
for spec_element in &format_spec.elements {
|
||||||
|
self.infer_fstring_element(spec_element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(clippy::unused_self)]
|
#[allow(clippy::unused_self)]
|
||||||
fn infer_ellipsis_literal_expression(
|
fn infer_ellipsis_literal_expression(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue