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 p 8000 otentially 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

Conversation

Avasam
Copy link
Collaborator
@Avasam Avasam commented Feb 18, 2023

Fixes "potentially unbound" type issues in stubsabot.
Simplify a bit the section about finding the first py.typed version and whether the stub is obsolete.

Copy link
Collaborator
@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Let's keep the diff_analysis where it was so we don't have to do work for obsolete stubs

@Avasam
Copy link
Collaborator Author
Avasam commented Feb 18, 2023

Let's keep the diff_analysis where it was so we don't have to do work for obsolete stubs

Oh yeah, I see. New commit should do that and still avoid "potentially unbound".

Comment on lines 441 to 442
*_, diff_url = diff_info
links["Diff"] = diff_url
Copy link
Collaborator Author
@Avasam Avasam Feb 18, 2023

Choose a reason for hiding this comment

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

I assume keeping the diff_url variable here is good for readability.
Although maybe this could be better if the returned tuple grows in the future?

Suggested change
*_, diff_url = diff_info
links["Diff"] = diff_url
diff_url = diff_info[3]
links["Diff"] = diff_url

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just realized you can do *_, links["Diff"] = diff_info. The worst of both worlds 😃 (looks neat though)

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!

@@ -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.

@@ -435,21 +438,22 @@ async def determine_action(stub_path: Path, session: aiohttp.ClientSession) -> U

diff_info = await get_diff_info(session, stub_info, pypi_info, relevant_version)
if diff_info is not None:
github_repo_path, old_tag, new_tag, diff_url = diff_info
*_, diff_url = diff_info
Copy link
Collaborator

Choose a reason for hiding this comment

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

diff_info is already a namedtuple, so let's use attribute access in both places instead of futzing with unpacking logic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Didn't see it was a named tuple. Yeah that'll be much better, even than teh original code.

@@ -170,8 +170,14 @@ 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, latest_release: PypiReleaseDownload, *, session: aiohttp.ClientSession
Copy link
Collaborator Author
@Avasam Avasam Feb 18, 2023

Choose a reason for hiding this comment

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

Technically latest_release can be obtained with pypi_info.get_latest_release(). But that would result in calling get_latest_release twice because it's also used for an early check.

I could leave this as-is, change the first parameter to expect the iterator of releases instead, or "cache" get_latest_release (for example by making it private and exposing it through a property that calls _get_latest_release only once), or any other idea.

Copy link
Collaborator Author
@Avasam Avasam Feb 18, 2023

Choose a reason for hiding this comment

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

Maybe it could return a bit less early, and use release_iter = pypi_info.releases_in_descending_order(). With the releases_in_descending_order moving in find_first_release_with_py_typed, building an iterator early is probably much better than a redundant call to pypi to get the latest release twice

Copy link
Collaborator
@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0