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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Equality operator not implemented on Requirement #325

Closed
lkollar opened this issue Jul 24, 2020 · 6 comments
Closed

Equality operator not implemented on Requirement #325

lkollar opened this issue Jul 24, 2020 · 6 comments

Comments

@lkollar
Copy link
Contributor

lkollar commented Jul 24, 2020

Reproducer:

>>> packaging.requirements.Requirement("a") == packaging.requirements.Requirement("a")
False

Is this expected behaviour?

@brettcannon
Copy link
Member

There's no comparison operator implemented on the class, so this may be on purpose. What's your specific use-case for wanting this? I ask because without a concrete version specifier of what's installed this is a very ephemeral thing.

And as a work-around, you could compare the string representations of the objects.

@lkollar
Copy link
Contributor Author

lkollar commented Jul 24, 2020

I was trying to do this in a test and was wondering why it doesn't have it implemented. I ended up working it around with the string comparison, just like you suggested.

I opened the issue mainly to clarify if this is an omission or if there is a good reason for not having it implemented. I don't have a strong opinion here. My only data point is that 'pkg_resources.Requirement' implements it, but I'm not even sure it's a goal at all to attempt any sort of compatibility with it.

@brettcannon
Copy link
Member

I don't know the history of the module to know if compatibility is in any way a goal.

@sbidoul
Copy link
Member

sbidoul commented Aug 2, 2020

I also stumbled on this requirement in a testing context. It would be nice to have.

@8day
Copy link

8day commented Sep 28, 2020

Comparison will require normalization of "dist; (((extra == 'doc')) and python_version == '3.8.6')" and "dist; 'doc' in extra and '3.8.6' in python_version" to "dist; python_version == '3.8.6' and extra == 'doc'", which requires a lot of work.

Also, considering that variable extra from environment markers is likely to be redefined in the near future, as discussed at https://discuss.python.org/t/the-extra-environment-marker-and-its-operators/, support for equality operator most likely will be added after such discussion will result in some PEP.

P.S. I am in no way related to PyPA, so these are just my two cents.

@pelson
Copy link
Contributor

pelson commented May 30, 2022

I was about to roll my sleeves up and implement this, when I saw that it has already been implemented in #499.

As a result of this:

>>> from packaging.requirements import Requirement

>>> Requirement('a==1') == Requirement('a== 1')"
True

And specifically, the motivating reproducer in the issues description is also working:

>>> import packaging.requirements 
>>> packaging.requirements.Requirement("a") == packaging.requirements.Requirement("a")
True

Therefore, suggest this can be closed.

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

No branches or pull requests

6 participants