# Buggy code
def __init__(
    self,
    link,  # type: Link
    template,  # type: InstallRequirement
    factory,  # type: Factory
    name=None,  # type: Optional[str]
    version=None,  # type: Optional[_BaseVersion]
):
    # type: (...) -> None
    source_link = link
    cache_entry = factory.get_wheel_cache_entry(link, name)
    if cache_entry is not None:
        logger.debug("Using cached wheel link: %s", cache_entry.link)
        link = cache_entry.link
    ireq = make_install_req_from_link(link, template)
    assert ireq.link == link
    if ireq.link.is_wheel and not ireq.link.is_file:
        wheel = Wheel(ireq.link.filename)
        wheel_name = canonicalize_name(wheel.name)
        assert name == wheel_name, "{!r} != {!r} for wheel".format(name, wheel_name)
        # Version may not be present for PEP 508 direct URLs
        if version is not None:
            assert str(version) == wheel.version, "{!r} != {!r} for wheel {}".format(
                version, wheel.version, name
            )

    if (
        cache_entry is not None
        and cache_entry.persistent
        and template.link is template.original_link
    ):
        ireq.original_link_is_in_wheel_cache = True

    super(LinkCandidate, self).__init__(
        link=link,
        source_link=source_link,
        ireq=ireq,
        factory=factory,
        name=name,
        version=version,
    )


# Traceback (KeyError)
Looking in indexes: https://pypi.anaconda.org/scipy-wheels-nightly/simple
Requirement already satisfied: numpy in /home/rgommers/anaconda3/envs/piptest/lib/python3.8/site-packages (1.17.3)
ERROR: Exception:
Traceback (most recent call last):
File "/home/rgommers/anaconda3/envs/piptest/lib/python3.8/site-packages/pip/_vendor/resolvelib/resolvers.py", line 186, in _merge_into_criterion
crit = self.state.criteria[name]
KeyError: 'numpy'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/rgommers/anaconda3/envs/piptest/lib/python3.8/site-packages/pip/_internal/cli/base_command.py", line 217, in _main
status = self.run(options, args)
File "/home/rgommers/anaconda3/envs/piptest/lib/python3.8/site-packages/pip/_internal/cli/req_command.py", line 180, in wrapper
return func(self, options, args)
File "/home/rgommers/anaconda3/envs/piptest/lib/python3.8/site-packages/pip/_internal/commands/install.py", line 318, in run
requirement_set = resolver.resolve(
File "/home/rgommers/anaconda3/envs/piptest/lib/python3.8/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 119, in resolve
self._result = resolver.resolve(
File "/home/rgommers/anaconda3/envs/piptest/lib/python3.8/site-packages/pip/_vendor/resolvelib/resolvers.py", line 427, in resolve
state = resolution.resolve(requirements, max_rounds=max_rounds)
File "/home/rgommers/anaconda3/envs/piptest/lib/python3.8/site-packages/pip/_vendor/resolvelib/resolvers.py", line 294, in resolve
name, crit = self._merge_into_criterion(r, parent=None)
File "/home/rgommers/anaconda3/envs/piptest/lib/python3.8/site-packages/pip/_vendor/resolvelib/resolvers.py", line 188, in _merge_into_criterion
crit = Criterion.from_requirement(self._p, requirement, parent)
File "/home/rgommers/anaconda3/envs/piptest/lib/python3.8/site-packages/pip/_vendor/resolvelib/resolvers.py", line 89, in from_requirement
if not candidates:
File "/home/rgommers/anaconda3/envs/piptest/lib/python3.8/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 96, in __bool__
return any(self)
File "/home/rgommers/anaconda3/envs/piptest/lib/python3.8/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 81, in __iter__
candidates = _insert_installed(self._installed, self._get_others())
File "/home/rgommers/anaconda3/envs/piptest/lib/python3.8/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 41, in _insert_installed
candidates = sorted(
File "/home/rgommers/anaconda3/envs/piptest/lib/python3.8/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 198, in iter_index_candidates
yield self._make_candidate_from_link(
File "/home/rgommers/anaconda3/envs/piptest/lib/python3.8/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 144, in _make_candidate_from_link
self._link_candidate_cache[link] = LinkCandidate(
File "/home/rgommers/anaconda3/envs/piptest/lib/python3.8/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 286, in __init__
assert str(version) == wheel.version, (
AssertionError: <Version('1.20.0.dev0+20201101041405.5c37621')> != '1.20.0.dev0+20201101041405-5c37621' for wheel numpy

# Fixed code
def __init__(
    self,
    link,  # type: Link
    template,  # type: InstallRequirement
    factory,  # type: Factory
    name=None,  # type: Optional[str]
    version=None,  # type: Optional[_BaseVersion]
):
    # type: (...) -> None
    source_link = link
    cache_entry = factory.get_wheel_cache_entry(link, name)
    if cache_entry is not None:
        logger.debug("Using cached wheel link: %s", cache_entry.link)
        link = cache_entry.link
    ireq = make_install_req_from_link(link, template)
    assert ireq.link == link
    if ireq.link.is_wheel and not ireq.link.is_file:
        wheel = Wheel(ireq.link.filename)
        wheel_name = canonicalize_name(wheel.name)
        assert name == wheel_name, "{!r} != {!r} for wheel".format(name, wheel_name)
        # Version may not be present for PEP 508 direct URLs
        if version is not None:
            wheel_version = Version(wheel.version)
            assert version == wheel_version, "{!r} != {!r} for wheel {}".format(
                version, wheel_version, name
            )

    if (
        cache_entry is not None
        and cache_entry.persistent
        and template.link is template.original_link
    ):
        ireq.original_link_is_in_wheel_cache = True

    super(LinkCandidate, self).__init__(
        link=link,
        source_link=source_link,
        ireq=ireq,
        factory=factory,
        name=name,
        version=version,
    )