GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix #1057: Preserve indentation when pasting code blocks by Piyush13104 · Pull Request #1059 · bpython/bpython

Conversation

@Piyush13104

@Piyush13104 Piyush13104 commented Oct 15, 2026

Copy link
Copy Markdown

Fixes #1057.

Pasting indented code could lose its indentation entirely. Reproduced by
driving bpython in a pty and rendering the screen through a terminal
emulator; there turned out to be two independent causes.

Tab events were dropped. just_simple_events() discarded any event
with len(e) > 1 that was not explicitly whitelisted, and <TAB> was
not on the list, so tab-indented code lost all indentation and produced
the reporter's exact error. preprocess.leading_tabs_to_spaces() exists
to convert pasted tabs, but was unreachable because tabs never survived
to reach it.

Runs of spaces were collapsed. compress_paste_event() treats a run
of identical named keys as a held-down key. <SPACE> is a named key in
curtsies, so any read of 8 or more consecutive spaces (the paste
threshold is 7 bytes) collapsed to one. Twelve pasted spaces produced a
single space.

just_simple_events(), is_simple_event() and compress_paste_event()
each kept their own copy of the same list of text-producing keys and had
drifted apart, which is how <TAB> was missed. They now share a
CONTENT_KEYS table.

Fixing those exposed a third problem: a statement at column 0 after a
block was swallowed into it, because pasted code has no blank line to
close the block. separate_blocks() inserts one. It distinguishes a
block awaiting its blank line from a buffer held open by an unclosed
bracket by testing whether appending blank lines makes it compile, and
leaves elif/else/except/finally and comments alone, so
if/else and try/except pastes are untouched.

The script from the issue now pastes and runs correctly. Added 17 tests
covering tab- and space-indented pastes, deep indentation, continuing
clauses, unindented bracket continuations, decorators, multi-line
strings and backslash continuations.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

beedell-roke reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Piyush Bhoyar
fix bpython#1057: Preserve indentation when pasting code blocks
0ef6e2b
@Piyush13104 Piyush13104 mentioned this pull request Oct 15, 2026
[Bug] python3-bpython-0:0.26-3.fc44.noarch removes all indentation of pasted code. #1057
Open
@codecov

codecov Bot commented Oct 19, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.80220% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.31%. Comparing base (1a919d3) to head (0ef6e2b).
⚠️ Report is 48 commits behind head on main.

Files with missing lines Patch % Lines
bpython/curtsiesfrontend/repl.py 77.77% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1059      +/-   ##
==========================================
- Coverage   76.51%   76.31%   -0.21%     
==========================================
  Files          62       61       -1     
  Lines        8308     8346      +38     
==========================================
+ Hits         6357     6369      +12     
- Misses       1951     1977      +26     

☔ 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.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[Bug] python3-bpython-0:0.26-3.fc44.noarch removes all indentation of pasted code.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@Piyush13104
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.