Commit 202ae93
Guard get_ipython() being Optional (fixes mypy on master) (#1088)
The linters workflow has been failing on master since IPython 9.16
started annotating get_ipython() as returning Optional[InteractiveShell]
(history_manager is optional too). mypy 2.3 reports four union-attr
errors in scalene_tracing.py and scalene_magics.py; the existing
"type: ignore[no-untyped-call, unused-ignore]" on those lines does not
cover that error code, and says so.
No commit caused this -- master's last linters run (2026-07-05) passed
and nothing has landed since, so it broke when CI's unpinned
"pip install mypy ruff ..." picked up the newer versions.
Guard both levels. _handle_jupyter_cell() returns False without a live
shell, falling through to the ordinary filename rules, which is the
behavior it already had when the cell regex didn't match. run_code()
prints a plain message and returns; neither value can actually be None
there, since a magic only runs inside a live shell.
The ignore comments stay put: on older IPython, get_ipython() is
untyped, so no-untyped-call still applies, and unused-ignore keeps the
comment valid once it doesn't.
Verified in a venv pinned to CI's exact versions (mypy 2.3.0, IPython
9.16.0): 4 errors before, clean after, ruff clean. Also re-checked
against the older pair (mypy 1.19.0, IPython 9.9.0) so the fix holds in
both directions. Behavior spot-checked for all three shapes -- live
shell (recovers the cell and returns True), get_ipython() None, and
history_manager None. Full pytest suite: 442 passed, 13 skipped.
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent c2e9e17 commit 202ae93
2 files changed
Lines changed: 24 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
44 | 57 | | |
45 | 58 | | |
46 | 59 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
157 | | - | |
158 | | - | |
159 | | - | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
160 | 167 | | |
161 | 168 | | |
162 | 169 | | |
| |||
0 commit comments