forked from Rust-related/RustPython
Merge pull request #1665 from youknowone/small-changes
Small changes about parser, int test, new_bool and socket.has_ipv6
This commit is contained in:
@@ -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]");
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -419,6 +419,7 @@ impl PyContext {
|
||||
)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn new_bool(&self, b: bool) -> PyObjectRef {
|
||||
let value = if b {
|
||||
&self.true_value
|
||||
|
||||
@@ -643,6 +643,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
|
||||
"htons" => ctx.new_rustfunc(socket_hton::<u16>),
|
||||
"ntohl" => ctx.new_rustfunc(socket_ntoh::<u32>),
|
||||
"ntohs" => ctx.new_rustfunc(socket_ntoh::<u16>),
|
||||
"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),
|
||||
|
||||
Reference in New Issue
Block a user