@@ -452,24 +452,23 @@ def get_applicable_candidates(
452452 # Using None infers from the specifier instead.
453453 allow_prereleases = self ._allow_all_prereleases or None
454454 specifier = self ._specifier
455- versions = {
456- str (v )
457- for v in specifier .filter (
458- # We turn the version object into a str here because otherwise
459- # when we're debundled but setuptools isn't, Python will see
460- # packaging.version.Version and
461- # pkg_resources._vendor.packaging.version.Version as different
462- # types. This way we'll use a str as a common data interchange
463- # format. If we stop using the pkg_resources provided specifier
464- # and start using our own, we can drop the cast to str().
465- (str (c .version ) for c in candidates ),
455+
456+ # We turn the version object into a str here because otherwise
457+ # when we're debundled but setuptools isn't, Python will see
458+ # packaging.version.Version and
459+ # pkg_resources._vendor.packaging.version.Version as different
460+ # types. This way we'll use a str as a common data interchange
461+ # format. If we stop using the pkg_resources provided specifier
462+ # and start using our own, we can drop the cast to str().
463+ candidates_and_versions = [(c , str (c .version )) for c in candidates ]
464+ versions = set (
465+ specifier .filter (
466+ (v for _ , v in candidates_and_versions ),
466467 prereleases = allow_prereleases ,
467468 )
468- }
469-
470- # Again, converting version to str to deal with debundling.
471- applicable_candidates = [c for c in candidates if str (c .version ) in versions ]
469+ )
472470
471+ applicable_candidates = [c for c , v in candidates_and_versions if v in versions ]
473472 filtered_applicable_candidates = filter_unallowed_hashes (
474473 candidates = applicable_candidates ,
475474 hashes = self ._hashes ,
0 commit comments