Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-120376: operator.in_ & operator.not_in #120379

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

Closed
wants to merge 4 commits into from
Closed

Conversation

dg-pb
Copy link
Contributor

@dg-pb dg-pb commented Jun 12, 2024

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM. I just left a minor suggestion for the docstring.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

Haha, in fact, the function already exists: https://docs.python.org/dev/library/operator.html#operator.contains

@bedevere-app
Copy link

bedevere-app bot commented Jun 12, 2024

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@dg-pb
Copy link
Contributor Author

dg-pb commented Jun 12, 2024

Haha, in fact, the function already exists: https://docs.python.org/dev/library/operator.html#operator.contains

Yes, aware of it. in_ is a reverse-argument order __contains__. not_in does not exist.

See, https://discuss.python.org/t/proposed-additions-to-operator/49846/16 for why adding these is potentially is a good idea.

@dg-pb
Copy link
Contributor Author

dg-pb commented Jun 14, 2024

@vstinner One last thing I can do to support this is to provide github use-case search result count:

336 - /operator\.contains\(b, a\)/
480 - /lambda a, b\: a in b/

And I have laid out my reasoning from personal experience in https://discuss.python.org/t/proposed-additions-to-operator/49846/16 providing a contrast with reversal of other functions.

@dg-pb
Copy link
Contributor Author

dg-pb commented Jun 14, 2024

I have made the requested changes; please review again

@bedevere-app
Copy link

bedevere-app bot commented Jun 14, 2024

Thanks for making the requested changes!

@vstinner: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from vstinner June 14, 2024 00:06
@nineteendo
Copy link
Contributor

nineteendo commented Jun 14, 2024

I have made the requested changes; please review again

That's not how that works, you haven't changed anything. You can ask to consider the information though.

Ideally you would use this: /lambda (\w+), (\w+): \1 in \2/, but that's not supported on GitHub.

@AlexWaygood
Copy link
Member

I agree with Victor and the others who have commented on the Discourse thread that it's not worth it to add a function that is identical to operator.contains() except for the reversed order of the arguments. It's not a goal for the operator module to be exhaustive over all possible operator-like convenience functions, and nor should it be.

I can see more of an argument for the not_in addition.

@nineteendo
Copy link
Contributor

nineteendo commented Jun 14, 2024

Hmm, wouldn't it be better to add not_contains() or contains_not() then? Otherwise you expect in_() to exist as well.

@picnixz
Copy link
Member

picnixz commented Jun 14, 2024

Personally, I would expect in if you give me contains so that's why I'm actually supportive of the in_ and not_in. Another reason is that I have is_ and not_is so... having the same for the in keyword felt natural to me.

@nineteendo
Copy link
Contributor

I suggest you close the issue and PR and create new ones for not_contains() or contains_not().

@dg-pb
Copy link
Contributor Author

dg-pb commented Jun 14, 2024

It's not a goal for the operator module to be exhaustive over all possible operator-like convenience functions, and nor should it be.

I agree, my motivation is based on a need and careful consideration.

People are implementing in_ in their own libraries. ~400 implementations with the exact search. How many more with different argument names or similar variations - unknown.

And I have explained why it makes sense to me and what sort of functionality it supports.

The fact these somewhat naturally fit in between contains and is&not_is is a supporting argument, not primary motivation.

@dg-pb dg-pb marked this pull request as draft June 17, 2024 01:06
@dg-pb dg-pb marked this pull request as ready for review June 17, 2024 07:18
@dg-pb
Copy link
Contributor Author

dg-pb commented Jun 17, 2024

I have re-evaluated and incorporated feedback as best as I could.

So I wavered a bit on this one, but came back to my initial position.

What made up my mind was the fact that in and not in provide default argument order in ast:

Compare(
    left=Name(id='a', ctx=Load()),
        ops=[In()],
        comparators=[
        Name(id='b', ctx=Load())]))])

So they are generally useful utilities and also important functions for frameworks that build on ast.

not_contains is not as essential, because it follows argument order that is present in __contains__. Which is bound to return a bool/truth value, and is automatically inverted when invoked with not in. So there is no usefulness argument for it as __contains__ satisfy both in and not in.

While ast has In() and NotIn(), which are 2 independent operators.

@dg-pb
Copy link
Contributor Author

dg-pb commented Jun 17, 2024

I have made the requested changes; please review again

@bedevere-app
Copy link

bedevere-app bot commented Jun 17, 2024

Thanks for making the requested changes!

@vstinner: please review the changes made to this pull request.

@nineteendo
Copy link
Contributor

nineteendo commented Jun 17, 2024

I have made the requested changes; please review again

Again: don't say that if you haven't changed anything. You're supposed to "have made the requested changes".

If vstinner agrees with you after posting the new information, he'll drop his stale review. Otherwise you need to do what he told you to do.

@vstinner
Copy link
Member

@vstinner: please review the changes made to this pull request.

@AlexWaygood and I are against adding operator.in_(). Updating the same PR is not going to change my mind.

@dg-pb
Copy link
Contributor Author

dg-pb commented Jun 17, 2024

Updating the same PR is not going to change my mind.

I just thought providing new perspectives / arguments and addressing criticism can have an impact.

You kinda left me hanging there, I addressed criticism so I was expecting some response to why my reasoning doesn't cut it.

And I didn't mean to ping you this way second time, I was just testing how things work as there was still "change requested" and I thought maybe it reappeared because I converted it to draft and then back. Anyway.

Ok, closing this. Thank you for your time considering this.

@dg-pb dg-pb closed this Jun 17, 2024
@dg-pb dg-pb deleted the impl_120376 branch June 17, 2024 11:08
@dg-pb
Copy link
Contributor Author

dg-pb commented Jun 17, 2024

Again: don't say that if you haven't changed anything. You're supposed to "have made the requested changes".

If vstinner agrees with you after posting the new information, he'll drop his stale review. Otherwise you need to do what he told you to do.

He didn't tell me to do anything.

Generally, I am very confused by your interference. I don't need you explaining me the obvious.

@nineteendo
Copy link
Contributor

He didn't tell me to do anything.

He told you implicitly:

Haha, in fact, the function already exists: https://docs.python.org/dev/library/operator.html#operator.contains

If the function already exists (with different argument order), that means that it's not needed. (There should be one...)

I don't need you explaining me the obvious.

I am confused as to why you stated you made changes when you didn't, that's all. I'm totally fine with you arguing about it to try to change our mind.

@vstinner
Copy link
Member

I'm open to consider adding "not contains", but I'm not sure about the best name for that.

But I don't think that we should add in_(a,b) to just exchange argument order compare to contains(a,b).

@dg-pb
Copy link
Contributor Author

dg-pb commented Jun 17, 2024

I have no interest in not_contains, nor do I see its value. I will leave this to someone else then.

@vstinner
Copy link
Member

I have no interest in not_contains, nor do I see its value. I will leave this to someone else then.

Ok. Thanks for your contribution anyway. I was close to merge your PR when I saw that operator.in_() already exists, sorry about that :-) The PR itself LGTM, it just that we decided that in_() and contains() are redundant.

@dg-pb
Copy link
Contributor Author

dg-pb commented Jun 18, 2024

No worries at all, maybe it is for the best.

These 2 functions wouldn't solve the root of what is causing problems to me anyways.

Maybe I will have some better ideas down the line.

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

Successfully merging this pull request may close these issues.

5 participants