Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions Lib/_pyrepl/base_eventqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,11 @@ def empty(self) -> bool:
"""
return not self.events

def flush_buf(self) -> bytearray:
def flush_buf(self) -> bytes:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this method is redundant now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to remove the function. For now I kept it to keep the diff small. But happy to remove it and just use self.buf.take_bytes() instead. Let me know what you prefer.

"""
Flushes the buffer and returns its contents.
"""
old = self.buf
self.buf = bytearray()
return old
return self.buf.take_bytes() # type: ignore[attr-defined, no-any-return]

def insert(self, event: Event) -> None:
"""
Expand All @@ -87,7 +85,7 @@ def push(self, char: int | bytes) -> None:
if isinstance(k, dict):
self.keymap = k
else:
self.insert(Event('key', k, bytes(self.flush_buf())))
self.insert(Event('key', k, self.flush_buf()))
self.keymap = self.compiled_keymap

elif self.buf and self.buf[0] == 27: # escape
Expand All @@ -102,9 +100,9 @@ def push(self, char: int | bytes) -> None:

else:
try:
decoded = bytes(self.buf).decode(self.encoding)
decoded = self.buf.decode(self.encoding)
except UnicodeError:
return
else:
self.insert(Event('key', decoded, bytes(self.flush_buf())))
self.insert(Event('key', decoded, self.flush_buf()))
self.keymap = self.compiled_keymap
Loading