The Wayback Machine - https://web.archive.org/web/20241209190632/https://github.com/RustPython/RustPython/pull/2114
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow complex numbers as arguments of complex() #2114

Merged
merged 3 commits into from
Aug 15, 2020

Conversation

edwardycl
Copy link
Contributor

https://docs.python.org/3/library/functions.html#complex

Complex numbers can be arguments of complex()

Copy link
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like parsing real and parsing imag can share a part of code but doesn't have any idea. @coolreader18 how do you think about it?

@youknowone
Copy link
Member

Suggestion:

let real = if let Some(comp) = try_complex(real) {
    comp
} else if let Some(s) = real.payload_if_subclass::<PyString>() {
   ...
} else {
   ...
};
// imag same as real
...

let result = Complex64::new(real.re - imag.im, real.im + imag.re);
...

f.to_f64()
}
s @ PyString => {
let real: Complex64 = match real {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant type annotation

@youknowone
Copy link
Member

Thanks for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants