Environment
Description
I made env update in my project including pip as well. After that I wanted to check outdated packages with command:
pip list --outdated --format=columns
After that exception was raised.
Expected behavior
I expected list of packages or empty list.
How to Reproduce
pip list --outdated --format=columns
Output
(env) project (develop) $ pip list --outdated --format=columns
ERROR: Exception:
Traceback (most recent call last):
File "/project/env/lib/python3.6/site-packages/pip/_internal/cli/base_command.py", line 188, in main
status = self.run(options, args)
File "/project/env/lib/python3.6/site-packages/pip/_internal/commands/list.py", line 156, in run
packages = self.get_outdated(packages, options)
File "/project/env/lib/python3.6/site-packages/pip/_internal/commands/list.py", line 164, in get_outdated
dist for dist in self.iter_packages_latest_infos(packages, options)
File "/project/env/lib/python3.6/site-packages/pip/_internal/commands/list.py", line 164, in <listcomp>
dist for dist in self.iter_packages_latest_infos(packages, options)
File "/project/env/lib/python3.6/site-packages/pip/_internal/commands/list.py", line 195, in iter_packages_latest_infos
best_candidate = evaluator.get_best_candidate(all_candidates)
File "/project/env/lib/python3.6/site-packages/pip/_internal/index.py", line 729, in get_best_candidate
best_candidate = max(candidates, key=self._sort_key)
File "/project/env/lib/python3.6/site-packages/pip/_internal/index.py", line 710, in _sort_key
has_allowed_hash = int(link.is_hash_allowed(self._hashes))
File "/project/env/lib/python3.6/site-packages/pip/_internal/models/link.py", line 213, in is_hash_allowed
return hashes.is_hash_allowed(self.hash_name, hex_digest=self.hash)
AttributeError: 'NoneType' object has no attribute 'is_hash_allowed'
@ptynecki Thanks for filing this issue!
/cc @cjerdonek since he's worked on this part of the codebase and is more familiar with it than me.
Same issue on Windows 10, Python 3.7.3
Same issue on Ubuntu 18.04.2 LTS, Python 3.6.8
Same issue on macOS 18.6.0 and Python 3.7.4
Same issue on Windows 10, Python 3.7.4
Same issue on Fedora 29, Python 3.7.3.
For now, as a workaround, ...
python3 -m pip install -UI --user 'pip<19.2'
reinstalled pip
version 19.1.1. Although, the complete command output is curious.
$ python3 -m pip install -UI --user 'pip<19.2'
Collecting pip<19.2
Using cached https://files.pythonhosted.org/packages/5c/e0/be401c003291b56efc55aeba6a80ab790d3d4cece2778288d65323009420/pip-19.1.1-py2.py3-none-any.whl
Installing collected packages: pip
Successfully installed pip-19.2
Why does it report Successfully installed pip-19.2
?
Thanks for the confirmation of this occurring on multiple OSes!
Folks, if you're facing the same issue, please don't post additional comments. Please use GitHub reactions to upvote the first post and subscribe to the issue.
That way the maintainers would be able to have a discussion on how to resolve this in this issue -- additional "me too" comments won't help anyone.
Hmm, I guess the type checker failed us here. The type annotation says hashes
must be non-None, but it is None in the reported cases: https://github.com/pypa/pip/blob/369ec7c0a8a81a076ca5584c34c8530d7a30a220/src/pip/_internal/models/link.py#L202-L209
After a quick look, I think a good fix for now may be to update Link.is_hash_allowed(hashes)
to return False
if hashes
is None (and bring the annotation into alignment by updating the parameter to Optional[Hashes]
). That's probably simpler and more sure-fire at this point than trying to update things in possibly multiple places to ensure that the hashes
argument is always non-None
, especially since we can't seem to lean on the type checker to confirm with 100% certainty.
I guess the type checker failed us here.
Ahhh. Yep -- strict_optional is False for pip._internal.index
and this is exactly that failure.
we can't seem to lean on the type checker to confirm with 100% certainty.
Yea, we can't completely rely on it, as long as we have these flags for incremental adoption.
Ahhh. Yep -- strict_optional is False for pip._internal.index and this is exactly that failure.
And even though models/link.py
where the function is defined does have strict_optional
enabled.
Okay, I posted PR #6774 for this.
This issue tells me that a good step after this (for 19.3 -- not the patch release) will be to get strict_optional
turned on for index.py
..
And even though models/link.py where the function is defined does have strict_optional enabled.
Yea - mypy does checks at the call site, using the rules at the call site.
Your suggested fix and PR look good to me. If we don't see any other issue come up, I can do the bugfix release in the evening today -- ~3-5 hours from now.
If we don't see any other issue come up, I can do the bugfix release in the evening today -- ~3-5 hours from now.
That would be great. Thank you so much for doing that.
Hello. FWIW I may have found a bug in 19.2 that's unrelated to this one. I'm trying to figure it out still and will open a new issue afterwards.
EDIT:
Ah, someone already opened one https://github.com/pypa/pip/issues/6775
The fix is in master. I'll do the release in a bit -- getting a bit of rest after a long day today.
The release with this bug-fix has been uploaded. Thanks everyone (and especially @cjerdonek)! :)
Most helpful comment
The fix is in master. I'll do the release in a bit -- getting a bit of rest after a long day today.