Skip to content

Event.raw being added to itself instead of to another event's .raw in UnixConsole.getpending #145886

@devdanzin

Description

@devdanzin

Bug report

Bug description:

There is a small bug in _pyrepl.unix_console.UnixConsole.getpending, where instead of adding the raw data of event 2, we add the raw data of event 1 to itself:

e = Event("key", "", b"")
while not self.event_queue.empty():
e2 = self.event_queue.get()
e.data += e2.data
e.raw += e.raw

We can just fix the typo: e.raw += e.raw becomes e.raw += e2.raw. It's feasible to add a test for this.

But Event.raw isn't read anywhere and is untested. The 3 callers of getpending() only use ev.data or pending.data. The .raw field is only written to, never consumed. So we can simply remove it from Event and adapt some lines (summary below written with Claude Code).

Please let me know which solution is preferred and I can write a trivial PR to implement it.


Since .raw is never read by any consumer, it's dead code. This removes the field and all assignments to it:

console.py — Remove raw from the dataclass:

@dataclass
class Event:
    evt: str
    data: str

unix_console.py — Remove all raw-related code in both getpending variants:

  • Line 540: Event("key", "", b"")Event("key", "")
  • Line 545: delete e.raw += e.raw
  • Line 549-550: raw = ... / data = str(raw, ...)data = str(self.__read(amount), ...)
  • Line 552: delete e.raw += raw
  • Same changes for lines 564, 569, 572-575

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    easystdlibStandard Library Python modules in the Lib/ directorytopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions