Skip to content

Implement dict doc & reversed magic method#2172

Merged
youknowone merged 5 commits into
RustPython:masterfrom
mode9:master
Sep 11, 2020
Merged

Implement dict doc & reversed magic method#2172
youknowone merged 5 commits into
RustPython:masterfrom
mode9:master

Conversation

@mode9
Copy link
Copy Markdown
Contributor

@mode9 mode9 commented Aug 31, 2020

Implement a document and reversed feature of dictionary type.

  • Add dict_reversekeyiterator_type
  • Add dict_reversevalueiterator_type
  • Add dict_reverseitemiterator_type

Tests expect python 3.8 or higher (or RustPython)

@mode9 mode9 changed the title Implemented dict doc & reversed magic method Implement dict doc & reversed magic method Aug 31, 2020
Comment thread tests/snippets/builtin_dict.py Outdated
@@ -1,3 +1,5 @@
import pytest
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unfortunately, pytest is running the test but not available from the test code. See testutils.py. it includes assert_raises function which almost working like pytest.raises

Copy link
Copy Markdown
Contributor Author

@mode9 mode9 Aug 31, 2020

Choose a reason for hiding this comment

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

Could you tell me how to cPython test in local? It's succeeded in local. but failed in CI

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

README describes how to run test in local.
Roughly, running a single file is: python tests/snippets/builtin_dict.py

Comment thread vm/src/obj/objdict.rs Outdated
match self.dict.len().checked_sub(count) {
Some(mut pos) => {
let (key, value) = self.dict.entries.next_entry(&mut pos).unwrap();
self.position.store(count);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@palaviv can you check the atomicity of this?

Copy link
Copy Markdown
Member

@youknowone youknowone Sep 8, 2020

Choose a reason for hiding this comment

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

I think @palaviv was busy for a while. Because I don't want to keep this PR open for too long time, here is a suggestion:

let count = self.position.fetch_add(1);
match ... {
    Some(..) => ... // we don't nees to store a new value here. it already was `fetch_add`ed. and this is the hot path
    None => { self.position.store(std::isize::MAX as usize); ... } // prevent overflow here
}

the position will keep the atomicity and it will not be a big problem to set the value when it is already done

Copy link
Copy Markdown
Contributor Author

@mode9 mode9 Sep 10, 2020

Choose a reason for hiding this comment

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

I fixed this issue, but i'm not sure it's what you expected.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, it looks good to me. @coolreader18 is this ok?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yup

@youknowone
Copy link
Copy Markdown
Member

youknowone commented Sep 6, 2020

You chose a big work as a first contriibution ;) the PR generally looks good.

Normally, contributors never use merge command (including pull) in github projects. Only github does it.

Will you try to rebase your work?
When RustPython/RustPython is remote upstream, (try git remote add upstream https://github.com/RustPython/RustPython.git if you don't have one yet)
git rebase upstream/master will remove merge commits from your patch and attach your commits onto top of upstream/master.

@mode9
Copy link
Copy Markdown
Contributor Author

mode9 commented Sep 6, 2020

You chose a big work as a first contriibution ;) the PR generally looks good.

Normally, contributors never use merge command (including pull) in github projects. Only github does it.

Will you try to rebase your work?
When RustPython/RustPython is remote upstream, (try git remote add upstream https://github.com/RustPython/RustPython.git if you don't have one yet)
git rebase upstream/master will remove merge commits from your patch and attach your commits onto top of upstream/master.

Thank you for your advice. Thanks to rebase, Commit history got cleaned up.

@youknowone youknowone merged commit 3d88545 into RustPython:master Sep 11, 2020
@mode9 mode9 deleted the master branch June 8, 2022 04:03
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.

3 participants