From 5d50e19432788483c15411be18de107fbfdf5763 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Wed, 8 Jan 2020 11:52:49 +0900 Subject: [PATCH 1/4] dict comprehension test --- parser/src/parser.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/parser/src/parser.rs b/parser/src/parser.rs index 48db5846ae..7a2ddd248c 100644 --- a/parser/src/parser.rs +++ b/parser/src/parser.rs @@ -393,6 +393,31 @@ mod tests { ) } + #[test] + fn test_parse_dict_comprehension() { + let source = String::from("{x1: x2 for y in z}"); + let parse_ast = parse_expression(&source).unwrap(); + assert_eq!( + parse_ast, + ast::Expression { + location: ast::Location::new(1, 1), + node: ast::ExpressionType::Comprehension { + kind: Box::new(ast::ComprehensionKind::Dict { + key: mk_ident("x1", 1, 2), + value: mk_ident("x2", 1, 6), + }), + generators: vec![ast::Comprehension { + location: ast::Location::new(1, 9), + target: mk_ident("y", 1, 13), + iter: mk_ident("z", 1, 18), + ifs: vec![], + is_async: false, + }], + } + } + ); + } + #[test] fn test_parse_list_comprehension() { let source = String::from("[x for y in z]"); From bb9d09baaf3d0686a0fedf443fb20da1b46a4340 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Wed, 8 Jan 2020 11:53:00 +0900 Subject: [PATCH 2/4] bad int test snippet --- tests/snippets/ints.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/snippets/ints.py b/tests/snippets/ints.py index bffdc103dd..6f42c9489c 100644 --- a/tests/snippets/ints.py +++ b/tests/snippets/ints.py @@ -273,6 +273,13 @@ class F(float): assert int(F(1.2)) == 3 +class BadInt(int): + def __int__(self): + return 42.0 + +with assert_raises(TypeError): + int(BadInt()) + assert isinstance((0).__round__(), int) assert isinstance((1).__round__(), int) assert (0).__round__() == 0 From 88c295c7f41ad69a79d33009209fe78fdb396ad1 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Wed, 8 Jan 2020 11:53:41 +0900 Subject: [PATCH 3/4] inline new_bool --- vm/src/pyobject.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/vm/src/pyobject.rs b/vm/src/pyobject.rs index 17ceee9e6c..4888c6f2a1 100644 --- a/vm/src/pyobject.rs +++ b/vm/src/pyobject.rs @@ -419,6 +419,7 @@ impl PyContext { ) } + #[inline] pub fn new_bool(&self, b: bool) -> PyObjectRef { let value = if b { &self.true_value From 9d01ae295778d0bc00cf5a230adbc717f8019ff9 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Wed, 8 Jan 2020 11:53:51 +0900 Subject: [PATCH 4/4] socket.has_ipv6 as false (temporary) --- vm/src/stdlib/socket.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/vm/src/stdlib/socket.rs b/vm/src/stdlib/socket.rs index 2007b3f686..60adf40a87 100644 --- a/vm/src/stdlib/socket.rs +++ b/vm/src/stdlib/socket.rs @@ -643,6 +643,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef { "htons" => ctx.new_rustfunc(socket_hton::), "ntohl" => ctx.new_rustfunc(socket_ntoh::), "ntohs" => ctx.new_rustfunc(socket_ntoh::), + "has_ipv6" => ctx.new_bool(false), "getdefaulttimeout" => ctx.new_rustfunc(|vm: &VirtualMachine| vm.get_none()), "getaddrinfo" => ctx.new_rustfunc(socket_getaddrinfo), "gethostbyaddr" => ctx.new_rustfunc(socket_gethostbyaddr),