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
__str__ and __repr__ for asyncio.Task still omit arg values #83804
Comments
This is not very helpful if your gather or wait contains multiple versions of foo with different argument values:
Should just be:
Would probably take all of 5 minutes to implement and make a lot of people's lives easier. |
This could sometimes make the output verbose when the arguments themselves are tasks while including arguments in the signature in _format_coroutine. $ cat /tmp/foo.py
import asyncio async def foo(a, b): pass
async def main():
task = asyncio.create_task(foo(1, b=1))
task1 = asyncio.create_task(foo(1, b=task))
print(repr(task))
print(repr(task1))
asyncio.run(main()) $ python3.8 /tmp/foo.py
<Task pending name='Task-2' coro=<foo() running at /tmp/foo.py:3>>
<Task pending name='Task-3' coro=<foo() running at /tmp/foo.py:3>>
$ ./python.exe /tmp/foo.py
<Task pending name='Task-2' coro=<foo(a=1, b=1) running at /tmp/foo.py:3>>
<Task pending name='Task-3' coro=<foo(a=1, b=<Task pending name='Task-2' coro=<foo(a=1, b=1) running at /tmp/foo.py:3>>) running at /tmp/foo.py:3>> |
We could limit the length of the recursive __repr__ functions, and display partial reprs suffixed with ..., like in numpy for example. We can define that the maximum wanted length of a task repr would be, say, 80 characters, get the reprs of all task arguments, and if the sum length is more than the maximum we can trim the longest ones and suffix with a '...'. Maybe this restriction shouldn't be applied if python is built in debug mode. |
Not so easy to find a satisfactory generic approach. Task has a name exactly for the purpose of distinguishing similar but different tasks, please use it. Only the task creator knows how to name it better. |
|
We do agree with that. Making it work in the way that does not disturb people when a 10mb bytes string is passed is challenging. We could just cut everything after 100 characters, but it's not an ideal solution either.
So make it useful. You can concatenate critical arguments reprs to task names or make them informative in other way. If you're working with a third-party library that doesn't use task names consider making a PR. |
Oh I just learned that since python3.8 you can name individual tasks. Sorry for the confusion :) |
Great. I'll close this issue then as the proposed solution is actually not as straightforward as it seems. Task names exist specifically to solve this case. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: