python-trio / python-trio/trio

Lots of people don't know functools.partial; document it better

Open
#88 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

docs
Dominant language
Python
Stars
7.3k
Forks
431
Avg merge
2d 17h
Merged PRs (30d)
6

Description

First, if you care I wrote a curio/trio options for IPython's async repl integration (https://github.com/ipython/ipython/pull/10390)

One thing I came across, is that you can't pass kwargs easily to function passed to run/Nursery.spawn:

In [9]: n.spawn?
Signature: n.spawn(async_fn, *args, name=None)

I think, this is a perfect use for positional only for async_fn not to grab a name if you want **kwargs.
There was a recent discussion on python idea about positional only.

I don't see any clean way of fixing this, except with an ugly api of the type:

trio.run.options(clock=None, instruments=[])(async_fn, /, *args, **kwargs)

Where option would return a "configured" run.

or allow a args, kwargs (no stars) parameters which are used when *args is empty:

run(async_fn, *args, clock=None, instruments=[], async_fn_args=None, async_fn_kwargs=None )

In my case I worked around with a second function wrapper:

def _trio_runner(function, user_ns):
    import trio
    def loc(fun, user_ns):
        return fun(**user_ns)
    return trio.run(loc, function, user_ns)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the documentation for trio.run and Nursery.spawn, then compare the kwargs limitation with Python's functools.partial and the workaround shown in the issue. Done means the relevant API documentation explains how to pass arguments and keyword arguments and makes the intended usage clear.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.