mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-19 02:55:50 +00:00
Set annotation for function args
This commit is contained in:
parent
1125a529e7
commit
f6e25fc0cb
1 changed files with 19 additions and 1 deletions
|
@ -931,7 +931,7 @@ impl<O: OutputStream> Compiler<O> {
|
|||
num_annotations += 1;
|
||||
}
|
||||
|
||||
for arg in args.args.iter() {
|
||||
let mut visit_arg_annotation = |arg: &ast::Parameter| -> CompileResult<()> {
|
||||
if let Some(annotation) = &arg.annotation {
|
||||
self.emit(Instruction::LoadConst {
|
||||
value: bytecode::Constant::String {
|
||||
|
@ -941,6 +941,19 @@ impl<O: OutputStream> Compiler<O> {
|
|||
self.compile_expression(&annotation)?;
|
||||
num_annotations += 1;
|
||||
}
|
||||
Ok(())
|
||||
};
|
||||
|
||||
for arg in args.args.iter().chain(args.kwonlyargs.iter()) {
|
||||
visit_arg_annotation(arg)?;
|
||||
}
|
||||
|
||||
if let ast::Varargs::Named(arg) = &args.vararg {
|
||||
visit_arg_annotation(arg)?;
|
||||
}
|
||||
|
||||
if let ast::Varargs::Named(arg) = &args.kwarg {
|
||||
visit_arg_annotation(arg)?;
|
||||
}
|
||||
|
||||
if num_annotations > 0 {
|
||||
|
@ -1385,6 +1398,11 @@ impl<O: OutputStream> Compiler<O> {
|
|||
self.compile_store(target)?;
|
||||
}
|
||||
|
||||
// Annotations are only evaluated in a module or class.
|
||||
if self.ctx.in_func() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Compile annotation:
|
||||
self.compile_expression(annotation)?;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue