pypa / pypa/packaging

Marker comparisons silently switches from version comparison to lexicographically

Open
#633 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

packaging.markers
Dominant language
Python
Stars
751
Forks
324
Avg merge
12h 58m
Merged PRs (30d)
3

Description

Marker comparisons silently switch from version number comparison to stringly, lexicographical comparison, e.g. on python 3.10 and packaging 22.0:

>>> from packaging.requirements import Requirement
>>> Requirement('numpy; python_version >= "3.9."').marker.evaluate()
False
>>> Requirement('numpy; python_version >= "3.9"').marker.evaluate()
True

I'm not aware of any case where that behavior is intended and PEP 508 is fuzzy about this, so i'd propose to print a warning whenever one of the version_cmp operators gets used without valid PEP 440 versions, and amend PEP 508 / Dependency specifiers with that.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two Requirement marker.evaluate() examples from the issue, then trace the marker comparison path for version_cmp operators and invalid PEP 440 versions. Done should include agreed behavior for these comparisons, coverage for the reported Python 3.10 and packaging 22.0 case, and the proposed warning or documentation updates.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.