You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Inconsistent extra normalisation in Requirement.__str__ #845
I noticed what seems to be an inconsistent normalisation when running the following:
$ pipxrun--pythonpython3.12--pip-run'packaging==24.1'# Python 3.12.7 (main, Oct 1 2024, 08:52:11) [GCC 9.4.0] on linux# Type "help", "copyright", "credits" or "license" for more information.>>>frompackaging.requirementsimportRequirement>>>req1=Requirement('mariadb>=1.0.1; extra == "mariadb_connector"')
>>>str(req1)
'mariadb>=1.0.1; extra == "mariadb-connector"'>>>req2=Requirement('mariadb>=1.0.1; python_version >= "3" and extra == "mariadb_connector"')
>>>str(req2)
'mariadb>=1.0.1; python_version >= "3" and extra == "mariadb_connector"'
Here for req1, Requirement.__str__ normalises the extra to mariadb-connector, in accordance to PEP 685.
But when there are other markers involved like in req2, it seems to preserve the original value without normalisation.
Is this behaviour expected? It looks a bit inconsistent to me.
Related to #644 (comment).
changed the title [-]Possibly inconsistent `extra` normalisation in `Requirement.__str__`?[/-][+]Inconsistent `extra` normalisation in `Requirement.__str__`[/+]on Nov 4, 2024
$ pipxrun--pythonpython3.12--pip-run'packaging==24.2'# Python 3.12.7 (main, Oct 1 2024, 08:52:11) [GCC 9.4.0] on linux# Type "help", "copyright", "credits" or "license" for more information.>>>frompackaging.requirementsimportRequirement>>>req1=Requirement('mariadb>=1.0.1; extra == "mariadb_connector"')
>>>str(req1)
'mariadb>=1.0.1; extra == "mariadb-connector"'>>>req2=Requirement('mariadb>=1.0.1; python_version >= "3" and extra == "mariadb_connector"')
>>>str(req2)
'mariadb>=1.0.1; python_version >= "3" and extra == "mariadb_connector"'
I believe this normalisation in the environment markers are implied by PEP 685:
Activity
[-]Possibly inconsistent `extra` normalisation in `Requirement.__str__`?[/-][+]Inconsistent `extra` normalisation in `Requirement.__str__`[/+]abravalheri commentedon Nov 11, 2024
This is still the behaviour in in 24.2:
I believe this normalisation in the environment markers are implied by PEP 685:
Now,
packagingitself is not writing anything, but it is what other tools use to normalise the requirements before writing.brettcannon commentedon Dec 9, 2024
I suspect we are not checking every key but just if there's a single key in the normalization case.