Skip to content

Preserve context between interactive commands - #1063

Merged
sebastinas merged 1 commit into
bpython:mainfrom
2836048681:fix/918-decimal-context
Nov 21, 2026
Merged

sebastinas merged 1 commit into
bpython:mainfrom
2836048681:fix/918-decimal-context

Conversation

@2836048681

Copy link
Copy Markdown

Repository: bpython/bpython

Issue: #918

Branch: fix/918-decimal-context

Commit: 9c2cbc8f985a90762c46ced69f0960611162b592

Description

CodeRunner executes each submitted command in a fresh greenlet. Greenlets
isolate contextvars, so the decimal context changed by one command was lost
when the next command ran. Preserve a copied context on the runner and execute
each command inside it. This keeps decimal settings (and other context-local
state) available between commands while isolating the REPL from the caller's
context.

Closes #918.

Tests

  • .venv/bin/pytest -q bpython/test/test_curtsies_coderunner.py bpython/test/test_interpreter.py — 11 passed, 4 subtests passed.
  • .venv/bin/pytest -q — 334 passed, 14 skipped, 3 xfailed, 16 subtests passed.
  • .venv/bin/python -m compileall -q bpython — passed.
  • git diff --check — passed.

The checkout is committed and clean. No push or pull request was created.

@codecov

codecov Bot commented Nov 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.44444% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 76.28%. Comparing base (1a919d3) to head (9c2cbc8).
⚠️ Report is 75 commits behind head on main.

Files with missing lines Patch % Lines
bpython/curtsiesfrontend/coderunner.py 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1063      +/-   ##
==========================================
- Coverage   76.51%   76.28%   -0.24%     
==========================================
  Files          62       60       -2     
  Lines        8308     8455     +147     
==========================================
+ Hits         6357     6450      +93     
- Misses       1951     2005      +54     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sebastinas
sebastinas merged commit 7d6b460 into bpython:main Nov 21, 2026
4 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

decimal.getcontext() is not applied within bpython

3 participants