Fix review: simplify fmt and normalize conditionals in dnd_command

Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/aa0821cf-6cf1-4fe5-ad76-904dba97aefa

Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-05-17 16:00:08 +00:00 committed by GitHub
parent d6886e0ccc
commit df9b906bc4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 2 additions and 7 deletions

View file

@ -304,16 +304,11 @@ def __call__(self, window_id: int, what: str, *a: Any) -> None:
if self.draw_dump_buf:
safe_print('draw', ''.join(self.draw_dump_buf))
self.draw_dump_buf = []
def encode_dict_value(v: Any) -> Any:
if isinstance(v, (bytes, memoryview)):
return str(v, 'utf-8', 'replace')
return v
def fmt(x: Any) -> Any:
if isinstance(x, (bytes, memoryview)):
return str(x, 'utf-8', 'replace')
if isinstance(x, dict):
return json.dumps({k: encode_dict_value(v) for k, v in x.items()})
return json.dumps({k: fmt(v) for k, v in x.items()})
return x
safe_print(what, *map(fmt, a), flush=True)
# }}}

View file

@ -289,7 +289,7 @@ def dnd_command(payload: str) -> None:
m += f':m={more}'
if (client_id := c.pop('client_id', None)):
m += f':i={client_id}'
if (operation := c.pop('operation', None)) is not None and operation:
if (operation := c.pop('operation', None)):
m += f':o={operation}'
if (cell_x := c.pop('cell_x', None)):
m += f':x={cell_x}'