Open
Conversation
Since CPython 3.12, `tb.tb_lineno` and `frame.f_lineno` can return None when the instruction at tb_lasti / f_lasti has no line mapping (for example certain async suspension points or synthetic RESUME/CACHE opcodes). `extraction.get_info` passed that None straight through to `source_inspection.annotate`, which blew up on `assert isinstance(lineno, int)`. Fall back to `frame.f_code.co_firstlineno` so a frame still renders instead of crashing downstream formatters. Adds a regression test that forces the None case via a synthetic TracebackType with out-of-range tb_lasti. Bumps version to 0.2.13. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Extend the test matrix so Python 3.12+ regressions like the one fixed in the previous commit get caught upstream instead of only in downstream consumers. Also adds a minimal .gitignore covering __pycache__, *.egg-info, build/, dist/, .venv*, and .pytest_cache so local dev doesn't leave untracked build artifacts in the worktree. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
Fixes issue where structured exception logging via stackprinter crashes on Python 3.12+ for certain tracebacks with `AssertionError` at `source_inspection.py:62` (and downstream `TypeError: '<=' not supported between instances of 'int' and 'NoneType'` in consumers like Loguru).
Root cause
Since CPython 3.12, `tb.tb_lineno` and `frame.f_lineno` can return `None` when the instruction at `tb_lasti` / `f_lasti` has no line mapping — e.g. synthetic RESUME/CACHE opcodes or certain async-suspension edge cases. `extraction.get_info` passed that `None` straight through to `source_inspection.annotate`, which blew up on `assert isinstance(lineno, int)`. In 3.11 `tb_lineno` was a plain `T_INT` PyMemberDef so the None path never existed — which is why the upstream maintainer is seeing it as a 3.14 regression even though the underlying CPython change landed in 3.12.
Confirmed by reading `Python/traceback.c`'s `tb_lineno_get` at the v3.14.2 tag (`Py_RETURN_NONE` when `PyCode_Addr2Line(code, lasti) < 0`), and reproduced locally with a synthetic `types.TracebackType(None, frame, 1<<20, -1)` that triggers the exact crash from production.
Changes
Test plan
🤖 Generated with Claude Code