use packaging.utils.canonicalize_name() #6022
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
poetry
currently has two different versions ofcanonicalize_name()
floating around, which is slightly absurd - and what's worse, they don't even agree.Since python-poetry/poetry-core#328,
poetry-core
has an implementation that agrees with the implementation inpackaging
- butpoetry
has its own implementation that continues to disagree with that. Sometimespoetry
uses one of these, and sometimes the other.Let's treat the version from
packaging
as the canonicalcanonicalize_name()
, and get rid of both of the re-implementations.I don't know that this fixes - or breaks! - anything in particular; the unit tests don't detect a difference. But two differing implementations is surely an accident waiting to happen.
Aside from being one-true-implementation, a potential advantage of the
packaging
version is that it returns aNormalizedName
: which is a newtype around string, rather than a plain string. That opens the door to future work in which the typechecker can verify that places which expect canonicalized names do indeed get them.(Will follow up in
poetry-core
, but this one will need merging first sincepoetry
sometimes uses thepoetry-core
version).