-
-
Notifications
You must be signed in to change notification settings - Fork 32k
RuntimeWarning "coroutine was never awaited" prints first line of file called sys #117535
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
Comments
I did not quite get the issue, do you mean why |
The string |
Hypothesis: The thing that shows the warning wants to actually show the first line of the sys module. Whether or not it makes sense to show the first line of the sys module I don't know. But it wrongly shows the first line of the |
Perhaps the weirdest thing is that I can git bisect this to the first ever 3.12 commit, which only changes the version :/ I have no idea how that's relevant, unless the behavior depends on the value of the Python version. |
Ahh, interesting. I believe I know what's going on. The warning module sent |
The output is supposed to include the source file name, the line number, the warning category name, and the warning message. $ echo 'open("/dev/null")' >example.py; ./python example.py
/home/serhiy/py/cpython3.12/example.py:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='/dev/null' mode='r' encoding='UTF-8'>
open("/dev/null")
ResourceWarning: Enable tracemalloc to get the object allocation traceback If the source is not a file, some special values like $ echo 'open("/dev/null")' | ./python
<stdin>:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='/dev/null' mode='r' encoding='UTF-8'>
ResourceWarning: Enable tracemalloc to get the object allocation traceback
$ ./python -c 'open("/dev/null")'
<string>:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='/dev/null' mode='r' encoding='UTF-8'>
ResourceWarning: Enable tracemalloc to get the object allocation traceback But if the warning is generated when no Python function frame exists, you get the "sys:1:" prefix: $ echo 'f = open("/dev/null")' >example.py; ./python example.py
sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='/dev/null' mode='r' encoding='UTF-8'>
$ echo 'f = open("/dev/null")' | ./python
sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='/dev/null' mode='r' encoding='UTF-8'>
$ ./python -c 'f = open("/dev/null")'
sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='/dev/null' mode='r' encoding='UTF-8'>
I considered several variants:
Omitting the prefix can produce less confusing for casual users output, but it is less informative. While we are here, I suggest also to change the line number from 1 to 0. It does not make any sense, since there are no source lines, but 0 looks more special than 1. |
This is fixed in both 3.12 and 3.13. Closing for complete. |
Thank you. |
Uh oh!
There was an error while loading. Please reload this page.
Bug report
Bug description:
Note the last line of the error. It is from the
sys
file.This does not go away when Python is invoked with
-P
,-E
, or-I
.CPython versions tested on:
3.12, 3.13
Operating systems tested on:
Linux
Linked PRs
sys
to<sys>
#118018The text was updated successfully, but these errors were encountered: