Repository: pypa/pip
File: src/pip/_internal/index/package_finder.py (Python)

Code before:
        if not version:
            version = _extract_version_from_fragment(
                egg_info,
                self._canonical_name,
            )
        if not version:
            reason = f"Missing project version for {self.project_name}"
            return (LinkType.format_invalid, reason)

        match = self._py_version_re.search(version)
        if match:
            version = version[: match.start()]
            py_version = match.group(1)
            if py_version != self._target_python.py_version:
                return (
                    LinkType.platform_mismatch,
                    "Python version is incorrect",
                )

        supports_python = _check_link_requires_python(
            link,
            version_info=self._target_python.py_version_info,
            ignore_requires_python=self._ignore_requires_python,
        )
        if not supports_python:
            rp_specs = specifiers.SpecifierSet(link.requires_python)
            rp_versions = []
            for rp_spec in rp_specs:
                rp_version = rp_spec.version
                if rp_spec.operator in ["==", "!="] and rp_version.endswith(".*"):
                    rp_version = rp_version[:-2]
                rp_versions.append(Version(rp_version))
            sorted_requires_python = ",".join(
                [str(s) for _, s in sorted(zip(rp_versions, rp_specs))]
            )
            reason = f"{version} Requires-Python {sorted_requires_python}"
            return (LinkType.requires_python_mismatch, reason)

        logger.debug("Found link %s, version: %s", link, version)

        return (LinkType.candidate, version)


def filter_unallowed_hashes(
    candidates: list[InstallationCandidate],
    hashes: Hashes | None,
    project_name: str,
) -> list[InstallationCandidate]:
    """
    Filter out candidates whose hashes aren't allowed, and return a new
    list of candidates.

Review comment (suggestion):
You should be able to pass requires python directly to `Specifier` rather than `SpecifierSet`.

Code after:
        if not version:
            version = _extract_version_from_fragment(
                egg_info,
                self._canonical_name,
            )
        if not version:
            reason = f"Missing project version for {self.project_name}"
            return (LinkType.format_invalid, reason)

        match = self._py_version_re.search(version)
        if match:
            version = version[: match.start()]
            py_version = match.group(1)
            if py_version != self._target_python.py_version:
                return (
                    LinkType.platform_mismatch,
                    "Python version is incorrect",
                )

        supports_python = _check_link_requires_python(
            link,
            version_info=self._target_python.py_version_info,
            ignore_requires_python=self._ignore_requires_python,
        )
        if not supports_python:
            requires_python = link.requires_python
            if requires_python:

                def get_version_sort_key(v: str) -> tuple[int, ...]:
                    return tuple(int(s) for s in v.split(".") if s.isdigit())

                requires_python = ",".join(
                    sorted(
                        (str(s) for s in specifiers.SpecifierSet(requires_python)),
                        key=get_version_sort_key,
                    )
                )
            reason = f"{version} Requires-Python {requires_python}"
            return (LinkType.requires_python_mismatch, reason)

        logger.debug("Found link %s, version: %s", link, version)

        return (LinkType.candidate, version)


def filter_unallowed_hashes(
    candidates: list[InstallationCandidate],
    hashes: Hashes | None,
    project_name: str,
) -> list[InstallationCandidate]:
    """