Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions trio/_core/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,9 @@ async def python_wrapper(orig_coro):
LOCALS_KEY_KI_PROTECTION_ENABLED, system_task
)

######
# Set up the Task object
######
task = Task._create(
coro=coro,
parent_nursery=nursery,
Expand Down
6 changes: 2 additions & 4 deletions trio/_core/tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -1698,10 +1698,9 @@ async def main():
async def f(): # pragma: no cover
pass

with ignore_coroutine_never_awaited_warnings():
with pytest.raises(TypeError, match="expecting an async function"):
with pytest.raises(TypeError, match="expecting an async function"):

Copy link
Member

Choose a reason for hiding this comment

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

No need for an extra blank line after with pytest.raises.

Copy link
Member

Choose a reason for hiding this comment

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

You marked this as resolved but didn't change anything in your PR. Do you feel like the extra blank lines here are important for readability in a way that's related to the changes you're making here? It seems like you've added a number of them in this diff after block introducers (for, with, if, etc). That's not consistent with the style in the rest of the codebase.

bad_call(f())
bad_call(f())

async def async_gen(arg): # pragma: no cover
yield arg
Expand All @@ -1710,7 +1709,6 @@ async def async_gen(arg): # pragma: no cover
TypeError,
match="expected an async function but got an async generator"
):

bad_call(async_gen, 0)


Expand Down
12 changes: 7 additions & 5 deletions trio/_threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def from_thread_run_sync(fn, *args, trio_token=None):
which would otherwise cause a deadlock.
AttributeError: if no ``trio_token`` was provided, and we can't infer
one from context. Also if ``fn`` is not a sync function.
Copy link
Member

Choose a reason for hiding this comment

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

This is leftover from your previous use of AttributeError for this condition, but you're now using TypeError.

Copy link
Member

Choose a reason for hiding this comment

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

You marked this as resolved but you didn't update the docstring.

Copy link
Member

Choose a reason for hiding this comment

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

You still have not updated the docstring despite having marked this as resolved again. The request is to remove the text "Also if fn is not a sync function" from the description for AttributeError, because you no longer raise AttributeError in that case.

TypeError: if ``fn`` is not callable or is an async function.
TypeError: if ``fn`` is an async function.

**Locating a Trio Token**: There are two ways to specify which
`trio.run` loop to reenter:
Expand All @@ -427,16 +427,18 @@ def from_thread_run_sync(fn, *args, trio_token=None):
def callback(q, fn, args):
@disable_ki_protection
def unprotected_fn():
call = fn(*args)
ret = fn(*args)

if inspect.iscoroutine(call):
call.close()
if inspect.iscoroutine(ret):

# Manually close coroutine to avoid RuntimeWarnings
ret.close()
raise TypeError(
"Trio expected a sync function, but {!r} appears to be "
"asynchronous".format(getattr(fn, "__qualname__", fn))
)

return call
return ret

res = outcome.capture(unprotected_fn)
q.put_nowait(res)
Expand Down
1 change: 0 additions & 1 deletion trio/tests/test_threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
)

from .._core.tests.test_ki import ki_self
from .._core.tests.tutil import ignore_coroutine_never_awaited_warnings


async def test_do_in_trio_thread():
Expand Down