1
1
"""Routines related to PyPI, indexes"""
2
+
2
3
from __future__ import annotations
3
4
4
5
import datetime
@@ -132,8 +133,8 @@ def __init__(
132
133
formats : frozenset [str ],
133
134
target_python : TargetPython ,
134
135
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 ,
137
138
) -> None :
138
139
"""
139
140
:param project_name: The user supplied package name.
@@ -152,6 +153,8 @@ def __init__(
152
153
PEP 503 "data-requires-python" values in HTML links. Defaults
153
154
to False.
154
155
: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.
155
158
"""
156
159
if ignore_requires_python is None :
157
160
ignore_requires_python = False
@@ -181,8 +184,15 @@ def evaluate_link(self, link: Link) -> tuple[LinkType, str]:
181
184
return (LinkType .yanked , f"yanked for reason: { reason } " )
182
185
183
186
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
+ )
186
196
return (LinkType .upload_too_late , reason )
187
197
188
198
if link .egg_fragment :
@@ -599,10 +609,10 @@ def __init__(
599
609
link_collector : LinkCollector ,
600
610
target_python : TargetPython ,
601
611
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 ,
606
616
) -> None :
607
617
"""
608
618
This constructor is primarily meant to be used by the create() class
@@ -647,9 +657,9 @@ def create(
647
657
cls ,
648
658
link_collector : LinkCollector ,
649
659
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 :
653
663
"""Create a PackageFinder.
654
664
655
665
:param selection_prefs: The candidate selection preferences, as a
0 commit comments