File tree Expand file tree Collapse file tree 3 files changed +9
-9
lines changed Expand file tree Collapse file tree 3 files changed +9
-9
lines changed Original file line number Diff line number Diff line change 1
1
2
2
# See also: https://github.com/RustPython/RustPython/issues/587
3
3
4
- def curry (foo : int , bla = 2 ) -> float :
4
+ def curry (foo : int , bla : int = 2 ) -> float :
5
5
return foo * 3.1415926 * bla
6
6
7
7
assert curry (2 ) > 10
8
+
9
+ print (curry .__annotations__ )
10
+ assert curry .__annotations__ ['foo' ] is int
11
+ assert curry .__annotations__ ['return' ] is float
12
+ assert curry .__annotations__ ['bla' ] is int
Original file line number Diff line number Diff line change @@ -440,7 +440,7 @@ impl Frame {
440
440
let _qualified_name = self . pop_value ( ) ;
441
441
let code_obj = self . pop_value ( ) ;
442
442
443
- let _annotations = if flags. contains ( bytecode:: FunctionOpArg :: HAS_ANNOTATIONS ) {
443
+ let annotations = if flags. contains ( bytecode:: FunctionOpArg :: HAS_ANNOTATIONS ) {
444
444
self . pop_value ( )
445
445
} else {
446
446
vm. new_dict ( )
@@ -457,13 +457,8 @@ impl Frame {
457
457
let scope = self . scope . clone ( ) ;
458
458
let obj = vm. ctx . new_function ( code_obj, scope, defaults) ;
459
459
460
- let annotation_repr = vm. to_pystr ( & _annotations ) ? ;
460
+ vm. ctx . set_attr ( & obj , "__annotations__" , annotations ) ;
461
461
462
- warn ! (
463
- "Type annotation must be stored in attribute! {:?}" ,
464
- annotation_repr
465
- ) ;
466
- // TODO: use annotations with set_attr here!
467
462
self . push_value ( obj) ;
468
463
Ok ( None )
469
464
}
Original file line number Diff line number Diff line change @@ -1566,7 +1566,7 @@ impl PyObject {
1566
1566
PyObject {
1567
1567
payload,
1568
1568
typ : Some ( typ) ,
1569
- dict : None ,
1569
+ dict : Some ( RefCell :: new ( PyAttributes :: new ( ) ) ) ,
1570
1570
}
1571
1571
. into_ref ( )
1572
1572
}
You can’t perform that action at this time.
0 commit comments