various small fixes#264
Conversation
…way). async112 error message now specifies if its nursery or taskgroup.
|
Don't think this needs a version/changelog bump, but it would probably be good to have some check for if the changelog is updated in a pull request as that's been missed in the past. |
|
I think the coverage failure on py39 is a bug in pytest-cov or coverage (??). I can reproduce it locally when running through tox. It's triggering here on line 130: flake8-async/flake8_async/visitors/visitors.py Lines 129 to 130 in f383fe6
[...] |
| Comma-separated list of methods which should be used with :meth:`trio.Nursery.start`/:meth:`anyio.abc.TaskGroup.start` when opening a context manager, | ||
| in addition to the default :func:`trio.run_process`, :func:`trio.serve_tcp`, :func:`trio.serve_ssl_over_tcp`, and :func:`trio.serve_listeners`. | ||
| Comma-separated list of methods which should be used with :meth:`trio.Nursery.start`/:meth:`anyio.abc.TaskGroup.start` when opening a context manager. | ||
| This includes startable functions in the trio and anyio standard library by default, namely :func:`trio.run_process`, :func:`trio.serve_tcp`, :func:`trio.serve_ssl_over_tcp`, :func:`trio.serve_listeners`, :func:`trio.serve`, :func:`anyio.run_process`, :func:`anyio.serve_tcp`, :func:`anyio.serve_ssl_over_tcp`, :func:`anyio.serve_listeners`, and :func:`anyio.serve`. |
There was a problem hiding this comment.
I think that the terms 'standard library' and 'by default' can be confusing here; I'd say something like "We then add known functions from AnyIO and Trio to this list, specifically [...]."
docs/usage.rst:268: WARNING: py:func reference target not found: trio.serve
docs/usage.rst:268: WARNING: py:func reference target not found: anyio.serve_tcp
docs/usage.rst:268: WARNING: py:func reference target not found: anyio.serve_ssl_over_tcp
docs/usage.rst:268: WARNING: py:func reference target not found: anyio.serve_listeners
docs/usage.rst:268: WARNING: py:func reference target not found: anyio.serve
docs/usage.rst:271: WARNING: undefined label: 'async114'
There was a problem hiding this comment.
Oh, turns out there is not a single function in anyio that takes a task_status parameter. The serve_xxx functions don't exist, and neither anyio.run_process has a task_status parameter nor any of the serve methods do. A search through the code and docs also reveal nothing. So ASYNC113 in fact does have several false alarms currently. Should change the code to also take into account the base of the attribute and not match on any xxx.run_process.
| with trio.open_nursery(10) as s: | ||
| s.shield = myvar | ||
| await foo() # safe in theory, error: 12, Statement("try/finally", lineno-6) | ||
| # this is not safe in theory - because `trio.open_nursery` is an async cm, | ||
| # so it's not possible to open a nursery at all. | ||
| await foo() # error: 12, Statement("try/finally", lineno-8) |
There was a problem hiding this comment.
So this should be async with, yeah? Also nurseries only checkpoint on exit, so I think it is safe?
There was a problem hiding this comment.
oh, huh. https://trio.readthedocs.io/en/stable/reference-core.html#trio.open_nursery does say "It does not block on entry" (and I guess block==checkpoint) and I tried it just now to confirm:
import trio
async def foo():
with trio.CancelScope() as cs:
cs.cancel()
async with trio.open_nursery() as nursery:
print("a")
nursery.cancel_scope.shield = True
await trio.lowlevel.checkpoint()
print("b")
print("c")
trio.run(foo)which prints all of a, b, and c.
So I guess we have double false alarms here, one because async with trio.open_nursery doesn't checkpoint, and one because we don't parse <nursery_name>.cancel_scope.[deadline/shield]
There was a problem hiding this comment.
wait, it doesn't block/checkpoint on exit either??
import trio
async def foo():
with trio.CancelScope() as cs:
cs.cancel()
async with trio.open_nursery():
print("in nursery")
print("after nursery")
trio.run(foo)$ python foo.py
in nursery
after nursery
There was a problem hiding this comment.
It does not block on entry; on exit it blocks until all child tasks have exited.
oh, hm. I guess that is meant to be read "if there are child tasks still alive, block until they have exited. If there are no child tasks, or they have all exited, it doesn't block."
Which in the end means that open_nursery never checkpoints on entry, and sometimes checkpoints on exit.
This reverts commit 2cf2519.
Zac-HD
left a comment
There was a problem hiding this comment.
LGTM overall; since this won't trigger a release let's deal with the false alarms in a follow-up 🙂
Various small fixes I noticed while going through code/doc/issues.
startable-in-context-manageropen_nurseryas a cancel scope.nursery.cancelscope.shield = True, only fornursery.shield = True, which is not possible)open_nurseryis itself an async function so you can't safely open a nursery anyway.