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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Stdlib] Add PythonObject.__contains__ #3101

Open
wants to merge 1 commit into
base: nightly
Choose a base branch
from

Conversation

rd4com
Copy link
Contributor

@rd4com rd4com commented Jun 22, 2024

Simple and small implementation,

Improving the 馃悕 Python experience !

Example usage:

x = PythonObject([1,2,3])
if 1 in x: 
   print("1 in x")

That method should be replaced by a c-python function if possible.

@rd4com rd4com requested a review from a team as a code owner June 22, 2024 04:38
@rd4com rd4com force-pushed the pythonobject_dunder_contains branch from b8315e3 to 8571772 Compare June 22, 2024 04:43
@rd4com rd4com requested a review from a team as a code owner June 22, 2024 05:04
@rd4com rd4com force-pushed the pythonobject_dunder_contains branch 2 times, most recently from 5a8c2ad to b4fc045 Compare June 26, 2024 16:14
Copy link
Collaborator

@JoeLoser JoeLoser left a comment

Choose a reason for hiding this comment

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

Great! Do you mind adding some unit tests please?

@JoeLoser JoeLoser self-assigned this Jun 26, 2024
@rd4com rd4com force-pushed the pythonobject_dunder_contains branch from b4fc045 to 8d364f9 Compare June 28, 2024 22:33
@rd4com
Copy link
Contributor Author

rd4com commented Jun 28, 2024

馃啎 unit tests

馃憤 yep it is important, should there be more ?

Python throws an error if the object is not iterable,

But mojo gets an internal error: PyObject_GetAttrString failed from it.

Current PR have a debug_assert when we have the error and returns False.

Is it possible to make __contains__ re-raise the same error as python would have thrown ?

@rd4com rd4com requested a review from JoeLoser June 28, 2024 22:49
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.

None yet

2 participants