You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
linecache.cache sometimes has an entry for <string> under Python 3.13.0a5 #117174
I noticed this via Hypothesis' pretty-printer for lambda functions, and tracked the divergence through the inspect module to linecache:
importlinecachedeftest():
print(linecache.cache["<string>"]) # expected to raise KeyErrorassertFalse
If I run this snippet with python3.13 -Wignore -m pytest repro.py, or any older Python version, you'll get the expected KeyError. But if I append -n2 to the command, it prints (44, None, ['import sys;exec(eval(sys.stdin.readline()))\n'], '<string>')!
(python3.13 -m pip install pytest pytest-xdist will get the dependencies for this)
That's the popen bootstrap line from execnet, which handles running code across multiple processes for pytest-xdist. At this point I've found linecache.cache.pop("<string>", None) to be an acceptable workaround, and since I don't have any particular knowledge of either the CPython or execnet code that's as far as I investigated.
The code above should trigger an exception because we should not be able to get the source of x (it's dynamically generated) but now it gives the full string.
I think a proper fix would be to change the code object name <string> for code passed with -c. <string> is commonly used for many dynamically generated code objects and if we want to do something special with the source code from -c we should name it differently. It might not be 100% backward compatible but I don't see a giant gap there. We can even keep the <string> in the traceback like what we did for python inputs.
A simpler way would be just disable this feature for -c - it's designed for interactive inputs and I don't even know if this is intentional or a pleasant side effect.
Or we could do even more aggressive and do similar numbering for dynamically compiled code and always give source code, which is a bit ambitious and definitely beyond this issue.
@pablogsal thoughts on this? I can do the PR if you want.
I have opened #117500 to do a renaming of the string to something less common. We still want to preserve this behaviour for -c since this still leads to better error locations and tracebacks.
Looking at the failures this is super wrong: (...)
_typing__idfunc is certainly not at ./Include/object.h:270
It's maybe time to declare game over and skip test_gdb if Python is built with LTO :-( We already skip test_gdb if Python is built with PGO or BOLT:
ifsupport.check_cflags_pgo():
raiseunittest.SkipTest("test_gdb is not reliable on PGO builds")
ifsupport.check_bolt_optimized():
raiseunittest.SkipTest("test_gdb is not reliable on BOLT optimized builds")
By the way, we recently modified test_gdb to also skip it if Python is built with clang -Og (commit 129db32).
Looking at the failures this is super wrong: (...)
_typing__idfunc is certainly not at ./Include/object.h:270
It's maybe time to declare game over and skip test_gdb if Python is built with LTO :-( We already skip test_gdb if Python is built with PGO or BOLT:
ifsupport.check_cflags_pgo():
raiseunittest.SkipTest("test_gdb is not reliable on PGO builds")
ifsupport.check_bolt_optimized():
raiseunittest.SkipTest("test_gdb is not reliable on BOLT optimized builds")
By the way, we recently modified test_gdb to also skip it if Python is built with clang -Og (commit 129db32).
Please let's not do it. The whole point of test gdb is to test that gdb works with released versions of CPython. If we skip it then gdb will be broken and we never know that the functionality works with the versions that people use it
Activity
gaogaotiantian commentedon Mar 26, 2024
I believe this is a feature from #110805 which allows the traceback to show source code with
python -c.3.12:
3.13:
However, I can see that the secret
<string>key in the cache causing issues forinspectbecause that module heavily relies on it. An example:The code above should trigger an exception because we should not be able to get the source of
x(it's dynamically generated) but now it gives the full string.I think a proper fix would be to change the code object name
<string>for code passed with-c.<string>is commonly used for many dynamically generated code objects and if we want to do something special with the source code from-cwe should name it differently. It might not be 100% backward compatible but I don't see a giant gap there. We can even keep the<string>in the traceback like what we did for python inputs.A simpler way would be just disable this feature for
-c- it's designed for interactive inputs and I don't even know if this is intentional or a pleasant side effect.Or we could do even more aggressive and do similar numbering for dynamically compiled code and always give source code, which is a bit ambitious and definitely beyond this issue.
@pablogsal thoughts on this? I can do the PR if you want.
pythongh-117174: Rename <string> to <__interactive_string__> for inte…
pythongh-117174: Rename <string> to <__interactive_string__> for inte…
pablogsal commentedon Apr 3, 2024
I have opened #117500 to do a renaming of the string to something less common. We still want to preserve this behaviour for
-csince this still leads to better error locations and tracebacks.pythongh-117174: Rename <string> to <__interactive_string__> for inte…
pythongh-117174: Respect tests that require environment variables wit…
gh-117174: Add a new route in linecache to fetch interactive source c…
pythongh-117174: Add a new route in linecache to fetch interactive so…
pythongh-117174: Adapt test_multiple_statements_fail_early now that w…
gh-117174: Adapt test_multiple_statements_fail_early now that we have…
[3.13] gh-117174: Add a new route in linecache to fetch interactive s…
encukou commentedon Mar 11, 2025
After this was merged I'm seeing failures like this:
pablogsal commentedon Mar 11, 2025
How this was not detected in the CI?
I will take a look later today
8 remaining items
[3.13] gh-117174: Fix reference leak and gdb tests (GH-131095) (#131120)
encukou commentedon Mar 12, 2025
@vstinner, do you have any ideas?
pythongh-117174: Skip test_gdb if Python is built with LTO
vstinner commentedon Mar 12, 2025
tl; dr I created PR gh-131143 to skip test_gdb if Python is built with LTO.
There are two important things on the AMD64 RHEL 8 buildbot:
I already noticed weird gdb behaviors when Python is built with LTO.
@pablogsal:
It's maybe time to declare game over and skip test_gdb if Python is built with LTO :-( We already skip test_gdb if Python is built with PGO or BOLT:
By the way, we recently modified test_gdb to also skip it if Python is built with
clang -Og(commit 129db32).pablogsal commentedon Mar 12, 2025
Please let's not do it. The whole point of test gdb is to test that gdb works with released versions of CPython. If we skip it then gdb will be broken and we never know that the functionality works with the versions that people use it
pablogsal commentedon Mar 12, 2025
I fixed the test failures by using a different function that doesn't get super optimised to wrong DWARF so at least we are fine for now
vstinner commentedon Mar 12, 2025
Oh, I didn't see that you already fixed the issue. That's why I was unable to reproduce it :-)
Ok, I abandon my PR skipping test_gdb is Python is built with LTO.
Adapt test to new REPL behavior (follow-up pythongh-117174)
gh-117174: Adapt `test_multiple_statements_fail_early` to new REPL be…
pythongh-117174: Adapt `test_multiple_statements_fail_early` to new R…
pythongh-117174: Adapt test_multiple_statements_fail_early now that w…
[3.13] gh-117174: Adapt test_multiple_statements_fail_early now that …
[3.13] gh-117174: Adapt `test_multiple_statements_fail_early` to new …
Copy `code.co_qualname` on Python >= 3.11
Copy `code.co_qualname` on Python >= 3.11 (#423)