File tree Expand file tree Collapse file tree 4 files changed +34
-0
lines changed Expand file tree Collapse file tree 4 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -393,6 +393,31 @@ mod tests {
393
393
)
394
394
}
395
395
396
+ #[ test]
397
+ fn test_parse_dict_comprehension ( ) {
398
+ let source = String :: from ( "{x1: x2 for y in z}" ) ;
399
+ let parse_ast = parse_expression ( & source) . unwrap ( ) ;
400
+ assert_eq ! (
401
+ parse_ast,
402
+ ast:: Expression {
403
+ location: ast:: Location :: new( 1 , 1 ) ,
404
+ node: ast:: ExpressionType :: Comprehension {
405
+ kind: Box :: new( ast:: ComprehensionKind :: Dict {
406
+ key: mk_ident( "x1" , 1 , 2 ) ,
407
+ value: mk_ident( "x2" , 1 , 6 ) ,
408
+ } ) ,
409
+ generators: vec![ ast:: Comprehension {
410
+ location: ast:: Location :: new( 1 , 9 ) ,
411
+ target: mk_ident( "y" , 1 , 13 ) ,
412
+ iter: mk_ident( "z" , 1 , 18 ) ,
413
+ ifs: vec![ ] ,
414
+ is_async: false ,
415
+ } ] ,
416
+ }
417
+ }
418
+ ) ;
419
+ }
420
+
396
421
#[ test]
397
422
fn test_parse_list_comprehension ( ) {
398
423
let source = String :: from ( "[x for y in z]" ) ;
Original file line number Diff line number Diff line change @@ -273,6 +273,13 @@ def __int__(self):
273
273
274
274
assert int (F (1.2 )) == 3
275
275
276
+ class BadInt (int ):
277
+ def __int__ (self ):
278
+ return 42.0
279
+
280
+ with assert_raises (TypeError ):
281
+ int (BadInt ())
282
+
276
283
assert isinstance ((0 ).__round__ (), int )
277
284
assert isinstance ((1 ).__round__ (), int )
278
285
assert (0 ).__round__ () == 0
Original file line number Diff line number Diff line change @@ -419,6 +419,7 @@ impl PyContext {
419
419
)
420
420
}
421
421
422
+ #[ inline]
422
423
pub fn new_bool ( & self , b : bool ) -> PyObjectRef {
423
424
let value = if b {
424
425
& self . true_value
Original file line number Diff line number Diff line change @@ -643,6 +643,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
643
643
"htons" => ctx. new_rustfunc( socket_hton:: <u16 >) ,
644
644
"ntohl" => ctx. new_rustfunc( socket_ntoh:: <u32 >) ,
645
645
"ntohs" => ctx. new_rustfunc( socket_ntoh:: <u16 >) ,
646
+ "has_ipv6" => ctx. new_bool( false ) ,
646
647
"getdefaulttimeout" => ctx. new_rustfunc( |vm: & VirtualMachine | vm. get_none( ) ) ,
647
648
"getaddrinfo" => ctx. new_rustfunc( socket_getaddrinfo) ,
648
649
"gethostbyaddr" => ctx. new_rustfunc( socket_gethostbyaddr) ,
You can’t perform that action at this time.
0 commit comments