`packaging.requirements.Requirement` not normalizing names, unlike `pkg_resources`

(Comes from Normalisation and Reqirement's `str()` · Issue #644 · pypa/packaging · GitHub)

Upon reading Core metadata specifications — Python Packaging User Guide

For comparison purposes, the names should be normalized before comparing.


>>> Requirement("A.B-C-D") == Requirement("A.B-C_D")


>>> pkg_resources.Requirement.parse("A.B-C-D") == pkg_resources.Requirement.parse("A.B-C_D")

Is this intended?

This seems like it’s specific to the packaging library, so it’s probably better raised as an issue with them. I’m not sure how I’d even go about comparing two general requirements (such as foo>1.0 and foo>=2.0, for example - they aren’t literally equal, but they may match the same set of releases if there’s no 1.x versions other than 1.0). The semantics of comparing Requirement objects is more a matter of what the library chooses than a standards matter IMO.

Probably not. You can find the code at packaging/requirements.py at 63f4cfe679fb3d9322e56d8569207ecff4735238 · pypa/packaging · GitHub which shows we are being a bit naive in comparisons.

Please open an issue at Issues · pypa/packaging · GitHub .

And it looks like someone (possibly the OP) left a comment at Normalisation and Reqirement's `str()` · Issue #644 · pypa/packaging · GitHub .

It was me, yes - thanks for confirming it. It was more of “is this behavior what’s being discussed in this issue”, which was not clear to me initially. We can continue the conversation there.