8000 Fix errors from upgrading · RustPython/RustPython@41878c8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 41878c8

Browse files
committed
Fix errors from upgrading
1 parent a46a74d commit 41878c8

File tree

< 8000 div class="d-flex flex-items-center">

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

common/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! A crate to hold types and functions common to all rustpython components.
22
3+
#![cfg_attr(target_os = "redox", feature(byte_slice_trim_ascii))]
4+
35
#[macro_use]
46
mod macros;
57
pub use macros::*;

vm/src/builtins/complex.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,27 @@ fn inner_pow(v1: Complex64, v2: Complex64, vm: &VirtualMachine) -> PyResult<Comp
131131
};
132132
}
133133

134-
let ans = v1.powc(v2);
134+
let ans = powc(v1, v2);
135135
if ans.is_infinite() && !(v1.is_infinite() || v2.is_infinite()) {
136136
Err(vm.new_overflow_error("complex exponentiation overflow".to_owned()))
137137
} else {
138138
Ok(ans)
139139
}
140140
}
141141

142+
// num-complex changed their powc() implementation in 0.4.4, making it incompatible
143+
// with what the regression tests expect. this is that old formula.
144+
fn powc(a: Complex64, exp: Complex64) -> Complex64 {
145+
let (r, theta) = a.to_polar();
146+
if r.is_zero() {
147+
return Complex64::new(r, r);
148+
}
149+
Complex64::from_polar(
150+
r.powf(exp.re) * (-exp.im * theta).exp(),
151+
exp.re * theta + exp.im * r.ln(),
152+
)
153+
}
154+
142155
impl Constructor for PyComplex {
143156
type Args = ComplexArgs;
144157

wasm/lib/src/browser_module.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ mod _browser {
7070
None => FetchResponseFormat::Text,
7171
};
7272

73-
let mut opts = web_sys::RequestInit::new();
73+
let opts = web_sys::RequestInit::new();
7474

7575
match method {
76-
Some(s) => opts.method(s.as_str()),
77-
None => opts.method("GET"),
76+
Some(s) => opts.set_method(s.as_str()),
77+
None => opts.set_method("GET"),
7878
};
7979

8080
if let Some(body) = body {
81-
opts.body(Some(&convert::py_to_js(vm, body)));
81+
opts.set_body(&convert::py_to_js(vm, body));
8282
}
8383

8484
let request = web_sys::Request::new_with_str_and_init(url.as_str(), &opts)
@@ -225,8 +225,8 @@ mod _browser {
225225
fn load_module(module: PyStrRef, path: PyStrRef, vm: &VirtualMachine) -> PyResult {
226226
let weak_vm = weak_vm(vm);
227227

228-
let mut opts = web_sys::RequestInit::new();
229-
opts.method("GET");
228+
let opts = web_sys::RequestInit::new();
229+
opts.set_method("GET");
230230

231231
let request = web_sys::Request::new_with_str_and_init(path.as_str(), &opts)
232232
.map_err(|err| convert::js_py_typeerror(vm, err))?;

0 commit comments

Comments
 (0)
0