Skip to content

Fix 'pip index versions' never printing the (latest) marker - #14178

Open
2ykwang wants to merge 5 commits into
pypa:mainfrom
2ykwang:fix-14177-latest-marker
Open

Fix 'pip index versions' never printing the (latest) marker#14178
2ykwang wants to merge 5 commits into
pypa:mainfrom
2ykwang:fix-14177-latest-marker

Conversation

@2ykwang

@2ykwang 2ykwang commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #14177.

The comparison was Version == str, which made the branch that prints (latest) unreachable.
Moves the existing parse_version(latest) call before the comparison and compares Version objects instead.

PR Checklist:

  • I agree to follow the PSF Code of Conduct.
  • I have read and have followed the CONTRIBUTING.md file.
  • I have added a news file fragment (or this PR does not need one).
  • I have read and followed the AI_POLICY.md file, and if any AI tools were used, I have disclosed it below.

[
("1.17.0", "1.17.0"),
# PEP 440 equality is not string equality.
("1.17", "1.17.0"),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for confirming @sepehr-rs I went with version parsing instead of str(). unlikely to ever matter in practice, but figured Version equality is the better comparison here.

In [1]: from packaging.version import Version

In [2]: Version("1.0") == Version("1.0.0")
Out[2]: True

In [3]: "1.0" == "1.0.0"
Out[3]: False

@sepehr-rs sepehr-rs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your contribution! Very nice call using version parsing instead of str().
Aside from a minor nit on the news file, this looks good to me. Thanks again!

Comment thread news/14177.bugfix.rst Outdated
Co-authored-by: Sepehr Rasouli <sepehrrasouli06@gmail.com>

@ichard26 ichard26 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an obvious bugfix, thanks for noticing and fixing this. My only concern is that this command is 100% something which be called and whose output will be parsed programmatically. So, despite this being an obvious defect, I'm not entirely sure it's worth the churn.

TBH, the command itself is confusing because the latest version is already included in the first line <pkg> (<latest-version>). I have no idea why we included the latest version twice originally.

$ pip index versions six
six (1.17.0)
Available versions: 1.17.0, 1.16.0, 1.15.0, 1.14.0, 1.13.0, 1.12.0, 1.11.0, 1.10.0, 1.9.0, 1.8.0, 1.7.3, 1.7.2, 1.7.1, 1.7.0, 1.6.1, 1.6.0, 1.5.2, 1.5.1, 1.5.0, 1.4.1, 1.4.0, 1.3.0, 1.2.0, 1.1.0, 1.0.0, 0.9.2, 0.9.1, 0.9.0
  INSTALLED: 1.17.0 (latest)

Ideally, people would be using --json but that wasn't added until much later...

@2ykwang

2ykwang commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @ichard26. the latest showing up twice made me curious too, so I dug into the git history a bit. most likely just a code slip.

The code that prints latest originally came from pip search which is probably also why the helper sits in search.py.

My guess is that:

  • A keyword search prints related packages across many rows, so printing an installed package on its own row didn't look out of place in search (that per-row line is how you could tell which of the results you already had installed).
  • When the index command was added it reused that helper (see code), and I doubt printing the latest version twice was intentional.

Also, FWIW the (latest) branch has been doing a str == Version comparison since the feature was first added, so it hasn't been working, and with no regression test it went unnoticed. plus, people probably didn't find it odd even without the (latest) marker showing.

Coming back to it. As you said this is a clear bug, but people might be parsing the LATEST: output. it's a string that's been printed for 4~5+ years and effectively works like a feature now, so I wouldn’t object to leaving it as-is either.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

'pip index versions' never prints the (latest) marker

3 participants