Skip to content

Adds __rmul__ to collections.deque #2844

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

Merged
merged 4 commits into from
Aug 11, 2021
Merged

Conversation

sobolevn
Copy link
Contributor

Closes #2834

Note: at the moment almost all collections are missing MemoryError corner case, like here: https://github.com/python/cpython/blob/d1ae57027fc39ff60dcfc1b63881400e5ca3ce56/Modules/_collectionsmodule.c#L709-L711

I guess that this is out of scope of this task, related:

I think that some tests in test_deque might hang because of that.

@sobolevn
Copy link
Contributor Author

Local test produces a very strange result:

» target/debug/rustpython 
Welcome to the magnificent Rust Python 0.1.2 interpreter 😱 🖖
>>>>> from collections import deque
>>>>> d = deque('abc', maxlen=5)
>>>>> d * 1 == deque('abc')
thread 'main' panicked at 'attempt to subtract with overflow', vm/src/stdlib/collections.rs:310:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@youknowone
Copy link
Member

d.len() is 3, maxlen is 5. so 3-5 is overflowed.

@DimitrisJim
Copy link
Member

I think that some tests in test_deque might hang because of that.

That's deadlocking, unfortunately. I've idly been trying to find a good way to tackle it. It is for another time, though.

let mul_len = mul.len();
let skipped = match self.maxlen.load() {
Some(maxlen) if mul_len > maxlen => mul_len - maxlen,
_ => 0,
Copy link
Member

@youknowone youknowone Aug 11, 2021

Choose a reason for hiding this comment

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

self.maxlen.load().and_then(|maxlen| mul_len.checked_sub(max_len)).unwrap_or(0)

edited wrapping_sub -> checked_sub

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

@DimitrisJim DimitrisJim merged commit 0906728 into RustPython:master Aug 11, 2021
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.

collections.deque does not have __rmul__ method
3 participants