8000 Fix potentially unbound issues in stubsabot by Avasam · Pull Request #9754 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

Fix potentially unbound issues in stubsabot #9754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 18, 2023
27 changes: 14 additions & 13 deletions scripts/stubsabot.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ async def release_contains_py_typed(release_to_download: PypiReleaseDownload, *,
raise AssertionError(f"Unknown package type: {packagetype!r}")


async def find_first_release_with_py_typed(pypi_info: PypiInfo, *, session: aiohttp.ClientSession) -> PypiReleaseDownload:
async def find_first_release_with_py_typed(pypi_info: PypiInfo, *, session: aiohttp.ClientSession) -> PypiReleaseDownload | None:
release_iter = pypi_info.releases_in_descending_order()
first_release_with_py_typed: PypiReleaseDownload | None = None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not change the signature of this method and just have it assert that the return value is not None. This really should only be called with the precondition that release_contains_py_typed was True, otherwise we'll just download all packages for all time

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively I'd also be fine with moving release_contains_py_typed into here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like 85a2d26 (#9754) ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, sorry I read a thing wrong, your change was fine as is!

while await release_contains_py_typed(release := next(release_iter), session=session):
if not release.version.is_prerelease:
first_release_with_py_typed = release
Expand Down Expand Up @@ -418,10 +419,12 @@ async def determine_action(stub_path: Path, session: aiohttp.ClientSession) -> U
if latest_version in spec:
return NoUpdate(stub_info.distribution, "up to date")

obsolete_since: PypiReleaseDownload | None = None
is_obsolete = await release_contains_py_typed(latest_release, session=session)
if is_obsolete:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let's get rid of is_obsolete and directly if await contains pytyped

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, wasn't sure if you'd like to keep the variable name just for readability.

first_release_with_py_typed = await find_first_release_with_py_typed(pypi_info, session=session)
relevant_version = version_obsolete_since = first_release_with_py_typed.version
obsolete_since = await find_first_release_with_py_typed(pypi_info, session=session)
assert obsolete_since is not None
relevant_version = obsolete_since.version
else:
relevant_version = latest_version

Expand All @@ -437,23 +440,21 @@ async def determine_action(stub_path: Path, session: aiohttp.ClientSession) -> U
if diff_info is not None:
github_repo_path, old_tag, new_tag, diff_url = diff_info
links["Diff"] = diff_url
diff_analysis = await analyze_diff(
github_repo_path=github_repo_path, stub_path=stub_path, old_tag=old_tag, new_tag=new_tag, session=session
)
else:
diff_analysis = None

if is_obsolete:
if obsolete_since:
return Obsolete(
stub_info.distribution,
stub_path,
obsolete_since_version=str(version_obsolete_since),
obsolete_since_date=first_release_with_py_typed.upload_date,
obsolete_since_version=str(obsolete_since.version),
obsolete_since_date=obsolete_since.upload_date,
links=links,
)

if diff_info is None:
diff_analysis: DiffAnalysis | None = None
else:
diff_analysis = await analyze_diff(
github_repo_path=github_repo_path, stub_path=stub_path, old_tag=old_tag, new_tag=new_tag, session=session
)

return Update(
distribution=stub_info.distribution,
stub_path=stub_path,
Expand Down
0