-
-
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
Add trio111, passing variables from context managers to nurseries opened outside them #22
Add trio111, passing variables from context managers to nurseries opened outside them #22
Conversation
e2d6f51
to
74ade78
Compare
Via python-trio/trio#671 (comment):
Yeah, you're entirely right; the nursery needs to be innermost not outermost. Important to note though that (to reduce false-alarms) we only want to warn if we have something from a context manager passed to the task(s) being started, and the context will exit before the nursery exits. We'll also want to check for |
Ah, so:
|
That's right! I'd check for any sync-or-async context manager to start. |
74ade78
to
f4f5f16
Compare
Haven't made a second pass through the code to clean up and add comments and stuff, but pushing a dirty version so you can check if the tests fit the specification.
"TRIO302": "call to nursery.start/start_soon with resource from context manager opened on line {} something something nursery on line {}",
I also found small bug in tester printer, will branch that off as separate PR. |
f4f5f16
to
e01300b
Compare
Fixed stuff mentioned above, though code is still dirty and uncommented. Wanna take a pass through it tomorrow morning with a fresh head. |
…async_context_manager
…most_async_context_manager
5339b30
to
bee9e3e
Compare
bee9e3e
to
e590e76
Compare
Merged in #34, so you should merge that before looking at the diff. Code should be all pretty and commented now~ ✨ |
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.
Check looks great; some comments about the message (tricky!) and the tests (also tricky 😅) but I think we'll probably ship this today!
flake8_trio.py
Outdated
"variable {2}, from context manager on line {0}, " | ||
"passed to {3} from nursery opened on {1}, might get closed while in use" |
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.
"variable {2}, from context manager on line {0}, " | |
"passed to {3} from nursery opened on {1}, might get closed while in use" | |
"variable {} is usable within the context manager on line {}, but that " | |
"will close before nursery opened on line {} - this is usually a bug. " | |
"Nurseries should generally be the inner-most context manager." |
Not super happy with this, but I think it gets at the core problem pretty directly. (message also requires some changes to the construction of the error, but dropping one and rearranging isn't too hard.)
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.
No need to drop/rearrange with indexed args, and redundant args getting ignored :P Long term maybe nice to do, but I think I'll leave the redundant arg for now for ease of putting it back.
There's also a question on how wordy one wants the error message to be, I personally prefer messages to be short enough to get shown as a one-liner in a status bar - esp the gist of them.
I'd maybe do something like
variable {2}, from context manager on line {0}, passed to {3} from nursery opened outside of it on line {1}, might get invalidly accessed due to context manager closing before the nursery.
(though not sure about invalidly vs illegally vs ??)
But I'll leave yours as is and let you decide.
Co-authored-by: Zac Hatfield-Dodds <[email protected]>
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.
Spent a while trying to come up with a message I liked more... and couldn't. Let's ship it!
A couple test cases I'm unsure how they should be handled, so make sure to check the test file thoroughly.
I'm also slightly confused about your definition of inner/outer - you say "should be outermost" but python-trio/trio#671 (comment) shows
being troublesome, which I'd call the nursery being the outer scope - and as such nurseries should be "innermost".
But easy to reverse logic / error message as needed.