Skip to content

Commit b1a9468

Browse files
committed
Improve stubsabot logic for finding the first release with a py.typed file
1 parent 7f986bd commit b1a9468

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

scripts/stubsabot.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,22 @@ async def find_first_release_with_py_typed(pypi_info: PypiInfo, *, session: aioh
174174
release_iter = pypi_info.releases_in_descending_order()
175175
while await release_contains_py_typed(release := next(release_iter), session=session):
176176
first_release_with_py_typed = release
177-
return first_release_with_py_typed
177+
first_version_with_py_typed = first_release_with_py_typed.version
178+
if not first_version_with_py_typed.is_prerelease:
179+
return first_release_with_py_typed
180+
normalised_versions_to_version_strings = {
181+
packaging.version.Version(version_string): version_string for version_string in pypi_info.releases
182+
}
183+
# We should be able to safely count on this being a non-empty iterable,
184+
# since this function hopefully won't be called
185+
# unless a non-prerelease version has been released
186+
# that has a py.typed file
187+
first_nonprerelease_version_with_py_typed = min(
188+
version
189+
for version in normalised_versions_to_version_strings
190+
if version > first_version_with_py_typed and not version.is_prerelease
191+
)
192+
return pypi_info.get_release(version=normalised_versions_to_version_strings[first_nonprerelease_version_with_py_typed])
178193

179194

180195
def _check_spec(updated_spec: str, version: packaging.version.Version) -> str:

0 commit comments

Comments
 (0)