Conversation
There was a problem hiding this comment.
Pull request overview
This PR modernizes and hardens pyinstrument’s profiling internals (Python + native), expands test coverage around edge cases (contextvars, frame metadata, IPython async), and updates the project’s formatting/linting + CI matrices (including Python 3.14).
Changes:
- Harden stack sampler / native profiler lifecycle handling (rollback on failure, safer contextvar reads, tighter native error handling).
- Preserve qualified class names in native frame identifiers and add regression tests for “no locals” and nested classes.
- Modernize tooling/CI: move import sorting/formatting to Ruff + add Nox lint session + expand CI/test/wheel matrices (incl. 3.14 and ARM runners).
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/test_threading.py | Reorders imports to match new lint/format tooling. |
| test/test_stack_sampler.py | Adds regression test ensuring failed subscribe rolls back sampler state. |
| test/test_pstats_renderer.py | Reorders imports to match new lint/format tooling. |
| test/test_profiler.py | Adds session root-frame regression test and minor assertion formatting changes. |
| test/test_profiler_async.py | Reorders imports to match new lint/format tooling. |
| test/test_processors.py | Reorders imports to match new lint/format tooling. |
| test/test_ipython_magic.py | Adds async/IPython cleanup tests and warning filtering; imports asyncio. |
| test/test_context_manager.py | Reorders imports to match new lint/format tooling. |
| test/low_level/test_frame_info.py | Adds tests for nested qualified class names and frames with no locals. |
| test/low_level/test_custom_timer.py | Adds regression test ensuring invalid timer return values don’t leak references. |
| test/low_level/test_context.py | Adds coverage for contextvars without defaults in low-level profiler. |
| pyproject.toml | Introduces Ruff configuration (line length/target/excludes/import sorting). |
| pyinstrument/stack_sampler.py | Adds rollback logic in subscribe() to restore state on failures. |
| pyinstrument/session.py | Fixes trimming logic when start call stack is empty. |
| pyinstrument/magic/magic.py | Refactors run_cell_async to improve IPython async compatibility and cleanup. |
| pyinstrument/low_level/stat_profile.c | Improves contextvar handling, refcounting on errors, qualified class name extraction, and error paths. |
| pyinstrument/low_level/stat_profile_python.py | Aligns contextvar .get(None) behavior with native implementation. |
| pyinstrument/frame.py | Minor assertion formatting change. |
| noxfile.py | Adds a lint session using prek; expands test session to Python 3.14. |
| metrics/overhead.py | Formatting-only change (string quoting in f-string). |
| .pre-commit-config.yaml | Replaces isort/Black hooks with Ruff check + Ruff format. |
| .github/workflows/wheels.yml | Updates wheel build matrix to include ARM runner and removes QEMU setup. |
| .github/workflows/test.yml | Expands test matrix to Python 3.14 (incl. ARM). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
joerick
marked this pull request as ready for review
July 29, 2026 19:41
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 AI text below 🤖
Draft for CI validation.
AI assistance: Amp was used to help develop and test these changes.