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 11
22# See also: https://github.com/RustPython/RustPython/issues/587
33
4- def curry (foo : int , bla = 2 ) -> float :
4+ def curry (foo : int , bla : int = 2 ) -> float :
55 return foo * 3.1415926 * bla
66
77assert 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 {
440440 let _qualified_name = self . pop_value ( ) ;
441441 let code_obj = self . pop_value ( ) ;
442442
443- let _annotations = if flags. contains ( bytecode:: FunctionOpArg :: HAS_ANNOTATIONS ) {
443+ let annotations = if flags. contains ( bytecode:: FunctionOpArg :: HAS_ANNOTATIONS ) {
444444 self . pop_value ( )
445445 } else {
446446 vm. new_dict ( )
@@ -457,13 +457,8 @@ impl Frame {
457457 let scope = self . scope . clone ( ) ;
458458 let obj = vm. ctx . new_function ( code_obj, scope, defaults) ;
459459
460- let annotation_repr = vm. to_pystr ( & _annotations ) ? ;
460+ vm. ctx . set_attr ( & obj , "__annotations__" , annotations ) ;
461461
462- warn ! (
463- "Type annotation must be stored in attribute! {:?}" ,
464- annotation_repr
465- ) ;
466- // TODO: use annotations with set_attr here!
467462 self . push_value ( obj) ;
468463 Ok ( None )
469464 }
Original file line number Diff line number Diff line change @@ -1566,7 +1566,7 @@ impl PyObject {
15661566 PyObject {
15671567 payload,
15681568 typ : Some ( typ) ,
1569- dict : None ,
1569+ dict : Some ( RefCell :: new ( PyAttributes :: new ( ) ) ) ,
15701570 }
15711571 . into_ref ( )
15721572 }
You can’t perform that action at this time.
0 commit comments