Skip to content

Add contains in dict_items#3259

Merged
youknowone merged 9 commits into
RustPython:mainfrom
Jack-R-lantern:__contains__
Oct 10, 2021
Merged

Add contains in dict_items#3259
youknowone merged 9 commits into
RustPython:mainfrom
Jack-R-lantern:__contains__

Conversation

@Jack-R-lantern

Copy link
Copy Markdown
Contributor

Added

PyDictItems::{contains}

test_case: builtin_dict.py l29 ~ l33

d = {'a': 123, 'b': 456}
assert ('a', 123) in d.items()
assert ('b', 456) in d.items()
assert ('a', 123, 3) not in d.items()
assert () not in d.items()

issues

cpython

>>> a={'a':1}
>>> 1 in a.items()
False
>>> 'a' in a.items()
False
>>>('a') in a.items()
False

rustpython

>>>>> a={'a':1}
>>>>> 1 in a.items()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Expected type 'tuple', not 'int'

>>>>> 'a' in a.items()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Expected type 'tuple', not 'str'

>>>>> ('a') in a.items()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Expected type 'tuple', not 'str'

@youknowone youknowone reopened this Oct 9, 2021
Comment thread extra_tests/snippets/builtin_dict.py Outdated
Comment thread vm/src/builtins/dict.rs Outdated
@eldpswp99

Copy link
Copy Markdown
Contributor

you can pass the fmt & clippy test by running
cargo fmt --all && cargo clippy

@youknowone youknowone left a comment

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.

This PR fixed test_dictitems_contains_use_after_free test in test_dict.py. Unmarking expectedFailure from this test will make CI pass.

See the output of CI job for details: https://github.com/RustPython/RustPython/pull/3259/checks?check_run_id=3845646437

Comment thread vm/src/builtins/dict.rs Outdated
Comment thread vm/src/builtins/dict.rs Outdated
Comment thread vm/src/builtins/dict.rs Outdated
Comment thread vm/src/builtins/dict.rs Outdated

@youknowone youknowone left a comment

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.

Looks good, thank you for contributing!

@youknowone youknowone merged commit eaae134 into RustPython:main Oct 10, 2021
@Jack-R-lantern

Copy link
Copy Markdown
Contributor Author

Thank you to everyone.

@Jack-R-lantern

Copy link
Copy Markdown
Contributor Author

Adding a ref to #2898 for trackability

@Jack-R-lantern Jack-R-lantern deleted the __contains__ branch October 10, 2021 05:26
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.

4 participants