11"""Routines related to PyPI, indexes"""
2+
23from __future__ import annotations
34
45import datetime
@@ -132,8 +133,8 @@ def __init__(
132133 formats : frozenset [str ],
133134 target_python : TargetPython ,
134135 allow_yanked : bool ,
135- ignore_requires_python : Optional [ bool ] = None ,
136- exclude_newer_than : Optional [ datetime .datetime ] = None ,
136+ ignore_requires_python : bool | None = None ,
137+ exclude_newer_than : datetime .datetime | None = None ,
137138 ) -> None :
138139 """
139140 :param project_name: The user supplied package name.
@@ -152,6 +153,8 @@ def __init__(
152153 PEP 503 "data-requires-python" values in HTML links. Defaults
153154 to False.
154155 :param exclude_newer_than: If set, only allow links prior to the given date.
156+ This should be a timezone-aware datetime. If a timezone-naive datetime
157+ is provided to the command line option, UTC is assumed.
155158 """
156159 if ignore_requires_python is None :
157160 ignore_requires_python = False
@@ -181,8 +184,15 @@ def evaluate_link(self, link: Link) -> tuple[LinkType, str]:
181184 return (LinkType .yanked , f"yanked for reason: { reason } " )
182185
183186 if link .upload_time is not None and self ._exclude_newer_than is not None :
184- if link .upload_time > self ._exclude_newer_than :
185- reason = f"Upload time { link .upload_time } after { self ._exclude_newer_than } "
187+ upload_time = link .upload_time
188+ assert upload_time .tzinfo is not None
189+ exclude_cutoff = self ._exclude_newer_than
190+ assert exclude_cutoff .tzinfo is not None
191+
192+ if upload_time > exclude_cutoff :
193+ reason = (
194+ f"Upload time { link .upload_time } after { self ._exclude_newer_than } "
195+ )
186196 return (LinkType .upload_too_late , reason )
187197
188198 if link .egg_fragment :
@@ -599,10 +609,10 @@ def __init__(
599609 link_collector : LinkCollector ,
600610 target_python : TargetPython ,
601611 allow_yanked : bool ,
602- format_control : Optional [ FormatControl ] = None ,
603- candidate_prefs : Optional [ CandidatePreferences ] = None ,
604- ignore_requires_python : Optional [ bool ] = None ,
605- exclude_newer_than : Optional [ datetime .datetime ] = None ,
612+ format_control : FormatControl | None = None ,
613+ candidate_prefs : CandidatePreferences | None = None ,
614+ ignore_requires_python : bool | None = None ,
615+ exclude_newer_than : datetime .datetime | None = None ,
606616 ) -> None :
607617 """
608618 This constructor is primarily meant to be used by the create() class
@@ -647,9 +657,9 @@ def create(
647657 cls ,
648658 link_collector : LinkCollector ,
649659 selection_prefs : SelectionPreferences ,
650- target_python : Optional [ TargetPython ] = None ,
651- exclude_newer_than : Optional [ datetime .datetime ] = None ,
652- ) -> " PackageFinder" :
660+ target_python : TargetPython | None = None ,
661+ exclude_newer_than : datetime .datetime | None = None ,
662+ ) -> PackageFinder :
653663 """Create a PackageFinder.
654664
655665 :param selection_prefs: The candidate selection preferences, as a
0 commit comments