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
Early tracing has lineno=None for modules #91067
Comments
Coverage.py has a trick to measure the early execution of stdlib modules. It has an "encodings.py" file that sets a trace function, then gets out of the way to let the real encodings.py execute. In 3.11.0a5, that early trace function gets None values for the line numbers when modules were first executed. To reproduce, create two files, encodings.py and prog.py: --- 8< ------------------------------------------ # encodings.py
import sys
class FullCoverageTracer:
def __init__(self):
self.traces = []
def fullcoverage_trace(self, *args):
frame, event, arg = args
if frame.f_lineno is None:
self.traces.append((frame.f_code.co_name, frame.f_code.co_filename))
return self.fullcoverage_trace
sys.settrace(FullCoverageTracer().fullcoverage_trace)
parentdir = max(filter(__file__.startswith, sys.path), key=len)
sys.path.remove(parentdir)
del sys.modules['encodings']
import encodings --- 8< ------------------------------------------ # prog.py
import sys
print(sys.version)
trace = sys.gettrace()
print("None traces:", trace.__self__.traces)
print("Hello") Then run:
|
This is a bit of a tricky one. The problem is that the line number for an instruction is used for two purposes.
If we set the lineno for the initial RESUME instruction in a module, we break dis and coverage for modules that do not have code on line 1. If we add an explicit line-start table, we would be able to fix this, as the RESUME would have a line number for case 1, but wouldn't start a line, thus not breaking dis. An explicit line-start table has other advantages, so we probably will implement it, but maybe not until 3.12. Ned, |
Maybe I'm missing something during normal execution, but I'm only seeing this effect now during this super-early encodings.py trick. I don't mind just special-casing the Nones in this case. |
#90973 is about implementing the line start table. |
@nedbat what is the status of this? Is it still an issue? (We've abandoned 90973 because it's no longer needed). |
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: