FIX: missing line events for raise statements and finally: ... bodies in Python 3.12+#356
Conversation
line_profiler/_line_profiler.pyx
Added handling for `sys.monitoring.events.RAISE` and `.RERAISE`
tests/test_line_profiler.py::test_profiling_exception()
New test for checking whether `raise` statements and `finally: ...`
bodies are properly profiled
raise statements and finally: ... bodies
raise statements and finally: ... bodiesraise statements and finally: ... bodies in Python 3.12+
|
For some weird reasons the
I think that the behavior in every other version should be the correct one, and thus just XFailed the test on 3.9. @Erotemic do you think we should investigate further into this discrepancy or just let it be? |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #356 +/- ##
=======================================
Coverage 87.36% 87.36%
=======================================
Files 18 18
Lines 1630 1630
Branches 347 347
=======================================
Hits 1424 1424
Misses 151 151
Partials 55 55 Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Usually I want to dive into these sort of things, but 3.9 is so close to end of life, that I'm very tempted to say let it be. I think we could just document it, and maybe come back to it later. I want to keep supporting 3.8+ for awhile, but profiling on raise and finally statements might be niche enough where nobody actually using 3.9 is impacted or notices. Does it work in current or older versions? Or is it something that's always been bugged? I'm also thinking that we've added so much, even though we aren't breaking backwards compat, we do a major version bump anyway, and then do another if we decide to change APIs. If there are fixes that need to be applied after we do the next release, it will be easier to see 5.0 as the breakpoint rather than 4.3. |
|
As far as I can tell the behavior is consistent on 3.8, 3.10, and 3.11 (and now also 3.12+ after the fix), so it isn't so much a backward compatibility problem but a quirk of 3.9 and 3.9 alone. Again, I can't seem to locate the root cause, but as you've said 3.9 is due for EoL in months; so yeah I agree, it should be okay for us to handle it this way. I don't personally have a preference towards either 4.3 vs 5.0; on the one hand we've extensively (if I may say so) extended the features, and a major bump might be good for advertising that, but on the other we haven't really broken existing APIs (at least in obvious ways) so SemVer dictates a minor bump... |
(Closes #355.)
Changes
line_profiler/_line_profiler.pyxAdded handling for
sys.monitoring.events.RAISEand.RERAISEtests/test_line_profiler.py::test_profiling_exception()New test for checking whether
raisestatements andfinally: ...bodies are properly profiled
Caveats
finallybody in atry: ... except: ... finally: ...block where the exception is re-raised (see e.g. action#1005). The exact reason for the failure is unclear, but I suspect it has to do with Python 3.9.0a2 changed how finally/return is traced python/cpython#83295.