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

New rule: don't return inside a nursery, nor break or continue an outer loop #261

Closed
Zac-HD opened this issue May 28, 2024 · 3 comments · Fixed by #282
Closed

New rule: don't return inside a nursery, nor break or continue an outer loop #261

Zac-HD opened this issue May 28, 2024 · 3 comments · Fixed by #282
Labels
enhancement New feature or request

Comments

@Zac-HD
Copy link
Member

Zac-HD commented May 28, 2024

See python-trio/trio#1493 - I'm not sure whether this is a good idea for a lint rule, but wanted to track it so I can decide later.

@jakkdl jakkdl added the postponed Low priority, blocked, or similar. label May 29, 2024
@Zac-HD Zac-HD added enhancement New feature or request and removed postponed Low priority, blocked, or similar. labels Aug 9, 2024
@Zac-HD
Copy link
Member Author

Zac-HD commented Aug 9, 2024

Per python-trio/trio#1493 (comment), let's do it!

I also like linting against break or continue for a loop outside the nursery, and think it makes sense to include that under the same rule.

@Zac-HD Zac-HD changed the title New rule: don't return a value inside a nursery? New rule: don't return inside a nursery, nor break or continue an outer loop Aug 9, 2024
@jakkdl
Copy link
Member

jakkdl commented Aug 27, 2024

This also applies to anyio, which appears to behave identically to trio regardless of backend.

I don't think it applies to asyncio, or at least I'm not able to manifest any counterintuitive behavior. This is largely because you cannot manually cancel their cancelscope-equivalents, and asyncio.Cancelled will always be transformed to a TimeoutError, so whenever you're losing the return value it's because you're getting an exception thrown in your face.

@oremanj
Copy link
Member

oremanj commented Aug 27, 2024

I think this is still fairly hazardous:

async with asyncio.TaskGroup() as tg:
    tg.create_task(do_something_forever())
    await asyncio.sleep(5)
    return "all done!"

The return value won't get lost per se, but one does tend to expect a return statement to result in the caller being resumed promptly. Here nothing happens until do_something_forever() completes or is cancelled.

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

Successfully merging a pull request may close this issue.

3 participants