Skip to content

Commit 73e6539

Browse files
authored
Merge pull request #1665 from youknowone/small-changes
Small changes about parser, int test, new_bool and socket.has_ipv6
2 parents 2473f8a + 9d01ae2 commit 73e6539

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

parser/src/parser.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,31 @@ mod tests {
393393
)
394394
}
395395

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+
396421
#[test]
397422
fn test_parse_list_comprehension() {
398423
let source = String::from("[x for y in z]");

tests/snippets/ints.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,13 @@ def __int__(self):
273273

274274
assert int(F(1.2)) == 3
275275

276+
class BadInt(int):
277+
def __int__(self):
278+
return 42.0
279+
280+
with assert_raises(TypeError):
281+
int(BadInt())
282+
276283
assert isinstance((0).__round__(), int)
277284
assert isinstance((1).__round__(), int)
278285
assert (0).__round__() == 0

vm/src/pyobject.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ impl PyContext {
419419
)
420420
}
421421

422+
#[inline]
422423
pub fn new_bool(&self, b: bool) -> PyObjectRef {
423424
let value = if b {
424425
&self.true_value

vm/src/stdlib/socket.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
643643
"htons" => ctx.new_rustfunc(socket_hton::<u16>),
644644
"ntohl" => ctx.new_rustfunc(socket_ntoh::<u32>),
645645
"ntohs" => ctx.new_rustfunc(socket_ntoh::<u16>),
646+
"has_ipv6" => ctx.new_bool(false),
646647
"getdefaulttimeout" => ctx.new_rustfunc(|vm: &VirtualMachine| vm.get_none()),
647648
"getaddrinfo" => ctx.new_rustfunc(socket_getaddrinfo),
648649
"gethostbyaddr" => ctx.new_rustfunc(socket_gethostbyaddr),

0 commit comments

Comments
 (0)