python-trio / python-trio/trio
Lots of people don't know functools.partial; document it better
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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