mirror of https://github.com/astral-sh/ruff
obey no_type_check when inferring params/return
This commit is contained in:
parent
5a0b99ffba
commit
69cfe4aed6
|
|
@ -177,8 +177,8 @@ impl<'db, 'ast> InferContext<'db, 'ast> {
|
|||
std::mem::replace(&mut self.multi_inference, multi_inference)
|
||||
}
|
||||
|
||||
pub(super) fn set_in_no_type_check(&mut self, no_type_check: InNoTypeCheck) {
|
||||
self.no_type_check = no_type_check;
|
||||
pub(super) fn set_in_no_type_check(&mut self, no_type_check: InNoTypeCheck) -> InNoTypeCheck {
|
||||
std::mem::replace(&mut self.no_type_check, no_type_check)
|
||||
}
|
||||
|
||||
fn is_in_no_type_check(&self) -> bool {
|
||||
|
|
|
|||
|
|
@ -2938,6 +2938,20 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
|
|||
definition: Definition<'db>,
|
||||
function: &ast::StmtFunctionDef,
|
||||
) {
|
||||
let mut prev_in_no_type_check = self.context.set_in_no_type_check(InNoTypeCheck::Yes);
|
||||
for decorator in &function.decorator_list {
|
||||
let decorator_type = self.infer_decorator(decorator);
|
||||
if let Type::FunctionLiteral(function) = decorator_type
|
||||
&& let Some(KnownFunction::NoTypeCheck) = function.known(self.db())
|
||||
{
|
||||
// If the function is decorated with the `no_type_check` decorator,
|
||||
// we need to suppress any errors that come after the decorators.
|
||||
prev_in_no_type_check = InNoTypeCheck::Yes;
|
||||
break;
|
||||
}
|
||||
}
|
||||
self.context.set_in_no_type_check(prev_in_no_type_check);
|
||||
|
||||
let previous_typevar_binding_context = self.typevar_binding_context.replace(definition);
|
||||
self.infer_return_type_annotation(
|
||||
function.returns.as_deref(),
|
||||
|
|
|
|||
Loading…
Reference in New Issue