Revert "[ty] Fix completion in decorator without class or function definition" (#22176)

This commit is contained in:
Micha Reiser
2025-12-24 17:27:21 +01:00
committed by GitHub
parent adef89eb7c
commit eef403f6cf
6 changed files with 22 additions and 165 deletions

View File

@@ -2914,27 +2914,21 @@ impl<'src> Parser<'src> {
self.current_token_range(),
);
let range = self.node_range(start);
ast::StmtFunctionDef {
node_index: Default::default(),
range,
is_async: false,
decorator_list: decorators,
name: ast::Identifier {
id: Name::empty(),
range: self.missing_node_range(),
node_index: AtomicNodeIndex::NONE,
},
type_params: None,
parameters: Box::new(ast::Parameters {
range: self.missing_node_range(),
..ast::Parameters::default()
}),
returns: None,
body: vec![],
}
.into()
// TODO(dhruvmanila): It seems that this recovery drops all the parsed
// decorators. Maybe we could convert them into statement expression
// with a flag indicating that this expression is part of a decorator.
// It's only possible to keep them if it's a function or class definition.
// We could possibly keep them if there's indentation error:
//
// ```python
// @decorator
// @decorator
// def foo(): ...
// ```
//
// Or, parse it as a binary expression where the left side is missing.
// We would need to convert each decorator into a binary expression.
self.parse_statement()
}
}
}