Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion tests/snippets/type_hints.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@

# See also: https://github.com/RustPython/RustPython/issues/587

def curry(foo: int, bla=2) -> float:
def curry(foo: int, bla: int =2) -> float:
return foo * 3.1415926 * bla

assert curry(2) > 10

print(curry.__annotations__)
assert curry.__annotations__['foo'] is int
assert curry.__annotations__['return'] is float
assert curry.__annotations__['bla'] is int
9 changes: 2 additions & 7 deletions vm/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ impl Frame {
let _qualified_name = self.pop_value();
let code_obj = self.pop_value();

let _annotations = if flags.contains(bytecode::FunctionOpArg::HAS_ANNOTATIONS) {
let annotations = if flags.contains(bytecode::FunctionOpArg::HAS_ANNOTATIONS) {
self.pop_value()
} else {
vm.new_dict()
Expand All @@ -470,13 +470,8 @@ impl Frame {
let scope = self.scope.clone();
let obj = vm.ctx.new_function(code_obj, scope, defaults);

let annotation_repr = vm.to_pystr(&_annotations)?;
vm.ctx.set_attr(&obj, "__annotations__", annotations);

warn!(
"Type annotation must be stored in attribute! {:?}",
annotation_repr
);
// TODO: use annotations with set_attr here!
self.push_value(obj);
Ok(None)
}
Expand Down
2 changes: 1 addition & 1 deletion vm/src/pyobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,7 @@ impl PyObject {
PyObject {
payload,
typ: Some(typ),
dict: None,
dict: Some(RefCell::new(PyAttributes::new())),
}
.into_ref()
}
Expand Down