-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Trio101: Never yield inside a nursery or cancel scope #4
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will review properly after the other PR is merged, but it looks like a good approach 👍
9c8c49a
to
ca0fa76
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Requesting a larger design change sorry, but I think it's worth it.
- It'd also be good to avoid false alarms on
@(async)contextmanager
-decorated functions, in which cases yielding inside these contexts is OK after all. Plus tests for that case. - New error codes should be added to the README, with as long a message as is needed to explain what's going on and how to fix it. (for that matter the existing TRIO100 message could use a link or two)
I should also check in explicitly - I rebased the branch for you so I could leave a meaningful review more promptly, motivated mostly by timezones. Happy to go with whatever branch strategy or convention is easier for you though, just let me know. |
I think it'll mostly be a one-time thing anyway, since once the setup is in place the pull requests will be much more independent. I think I prefer merging over rebasing to more easily see what changed when syncing to my local branches. |
better error message Co-authored-by: Zac Hatfield-Dodds <zac.hatfield.dodds@gmail.com>
I can give it a try, but not actually knowing Trio (and it usually not being too relevant for implementing the AST crawling) it'll require me to do a bunch of extra reading to write something educational (and correct). But I can give that a go later on. |
Let's just copy the error message from the code to the README then, and I'll improve the docs when we publish. |
Fixed. Small Q's: Unrelated to trio101 in particular, but: The fuzzer is way slower after your rewrite, idk if it's checking more files or something but I killed it after it ran for 3 minutes w/o completion on my system. |
|
Is there any official way to get markers on different lines in flake8? One of my regular linters (idk if it's pylint or mypy though lol) can put an error marker on one line that refers to another line that gets an info marker. Or we could add two "problems" one pointing to the yield and one pointing to the scope.
And
Hmm, I suppose that could be added as a parameter. But yeah lowering it to 1k (10x) tests still took my machine a minute 😇 |
… fuzz examples to 1k, detects contextmanagers in packages, disabled multithreading tests again
Any opinion on |
Do you want
to be detected? |
I meant to have the marker point at the But let's revisit this later, it can be retrofitted in a later PR.
Yep, you might just want to e.g. call
Some preference for local variables, because they're a simpler representation and much harder to mess with the representation. If we actually need access to other parts of the stack I'd change my mind.
I'd leave a comment to the effect of "We know that this doesn't handle We might later add a lint that complains if you do something fancier than just |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Merging now 😁
Ye I followed, but thought one could go a small step further and save people from having to look up line numbers - but unless there's a neat built-in way of doing it it might be ugly to raise two errors for one problem. |
Not entirely sure dumping a bunch of yields into a set is the best way to avoid false positives, but other than doing the reverse (saving
contextmanagers
/functiondefs
, or their linenos) I couldn't figure out a neater way of doing it.Didn't bother trying to juggle out trio100 changes, so you might want to merge the first pull request before looking at this diff.