Skip to content
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

Re-code flake8-trio and flake8-async rules to match upstream #10416

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

augustelalande
Copy link
Contributor

Summary

Re-code flake8-trio and flake8-async rules to match upstream. Resolves #10303.

Test Plan

@augustelalande
Copy link
Contributor Author

augustelalande commented Mar 15, 2024

This is mostly done, except for the previous ASYNC101 and ASYNC102 which don't exactly match any the of the new ASYNC rules. The closest matches are ASYNC220 and ASYNC222, but the behaviors don't match exactly. Part of the problem is that the previous rules should be split into multiple rules (this is easy). The other problem which I'm not sure how to resolve is that it doesn't seem like any of the new ASYNC rules check for time.sleep or open (nevermind ASYNC230 covers open), but this is a useful check that we should keep, so the question is what should I do?

Copy link
Contributor

github-actions bot commented Mar 15, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@augustelalande
Copy link
Contributor Author

Ok so I modified the implementation of ASYNC220 and ASYNC222, as well as added ASYNC221 so that the three rules would match the behavior of flake8-async. For now I added a check for time.sleep as part of ASYNC222.

@jakkdl
Copy link

jakkdl commented Mar 15, 2024

Oh, I'd missed that we don't check for time.sleep anymore. It's a bad match for ASYNC222, as the recommended replacement is using [trio/anyio/asyncio].sleep(), and not to wrap it in to_thread_run_sync or run_in_executor. I'll implement it quickly as ASYNC251

@augustelalande
Copy link
Contributor Author

augustelalande commented Mar 15, 2024

Ok I moved the time.sleep check to a newly created ASYNC251

@Zac-HD
Copy link

Zac-HD commented Mar 15, 2024

We've just released ASYNC251 upstream, so this is back to matching the merged flake8-async plugin.

@zanieb
Copy link
Member

zanieb commented Mar 15, 2024

Note that we'll need to add "redirects" for all of these rules, see rule_redirects.rs. See #9756 for example.

We may be able to make use of #9691 as well, not sure yet.

@augustelalande
Copy link
Contributor Author

Ok I added redirects for the old TRIO rules. But as mentioned the old ASYNC rules don't directly correspond to new ASYNC rules.

("TRIO109", "ASYNC109"),
("TRIO11", "ASYNC11"),
("TRIO110", "ASYNC110"),
("TRIO115", "ASYNC115"),
Copy link
Member

Choose a reason for hiding this comment

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

It looks like some ASYNC rules were also moved from one code to another.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ASYNC100 moved to ASYNC210, (but the ASYNC100 code was taken over by TRIO100)
ASYNC101 was split into ASYNC220, ASYNC221, ASYNC222, ASYNC230, and ASYNC251
ASYNC102 was merged into ASYNC220 and ASYNC221

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@charliermarsh any advice on this?

Copy link
Member

Choose a reason for hiding this comment

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

I think what you have here is right... The TRIO rules are gone, so lets redirect them away. But the ASYNC rules probably can't be safely redirected.

(Flake8Async, "221") => (RuleGroup::Preview, rules::flake8_async::rules::RunProcessInAsyncFunction),
(Flake8Async, "222") => (RuleGroup::Preview, rules::flake8_async::rules::WaitForProcessInAsyncFunction),
(Flake8Async, "230") => (RuleGroup::Preview, rules::flake8_async::rules::BlockingOpenCallInAsyncFunction),
(Flake8Async, "251") => (RuleGroup::Preview, rules::flake8_async::rules::BlockingSleepInAsyncFunction),
Copy link
Member

Choose a reason for hiding this comment

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

I think these probably shouldn't be in preview.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Up to you

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@jakkdl
Copy link

jakkdl commented May 17, 2024

I've got some comments on the human-friendly rule names you have, and it might be good if we synced them to ease transition between flake8-async and ruff. See python-trio/flake8-async#248 (comment)

(I'm sorry we're moving so quickly as of late 😁)

@JelleZijlstra
Copy link
Contributor

This PR has some merge conflicts now, anything I can do to help?

I'm motivated to add (the new) ASYNC101 to Ruff because of the problems mentioned in the draft PEP 789.

@charliermarsh
Copy link
Member

The main issue is that it's going to be a breaking change for users (e.g., ASYNC100 continues to exist but is now a different rule). We may be able to include it in v0.5.0 though which will be ~soon.

@charliermarsh charliermarsh added this to the v0.5.0 milestone May 23, 2024
@charliermarsh
Copy link
Member

@zanieb - let's include this in v0.5.0 since it's starting to cause problems.

@charliermarsh
Copy link
Member

@augustelalande -- I'm happy to take responsibility for resolving any conflicts.

@augustelalande
Copy link
Contributor Author

@charliermarsh I'll do it now. I'm also gonna update the rules with the new names from python-trio/flake8-async#248 (comment)

@augustelalande
Copy link
Contributor Author

Nevermind the last part. Updating all the rule names is a significant effort so should be a separate PR.

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.

Re-code flake8-trio and flake8-async rules to match upstream
6 participants