mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-19 15:04:50 +02:00
Make mypy 1.16 happy
This commit is contained in:
@@ -212,7 +212,7 @@ class ReadRequest(NamedTuple):
|
||||
id: str = ''
|
||||
protocol_type: ProtocolType = ProtocolType.osc_52
|
||||
|
||||
def encode_response(self, status: str = 'DATA', mime: str = '', payload: bytes = b'') -> bytes:
|
||||
def encode_response(self, status: str = 'DATA', mime: str = '', payload: bytes | memoryview = b'') -> bytes:
|
||||
ans = f'{self.protocol_type.value};type=read:status={status}'
|
||||
if status == 'OK' and self.is_primary_selection:
|
||||
ans += ':loc=primary'
|
||||
@@ -276,7 +276,7 @@ class WriteRequest:
|
||||
x = {mime: self.tempfile.create_chunker(pos.start, pos.size) for mime, pos in self.mime_map.items()}
|
||||
cp.set_mime(x)
|
||||
|
||||
def add_base64_data(self, data: str | bytes, mime: str = 'text/plain') -> None:
|
||||
def add_base64_data(self, data: str | bytes | memoryview, mime: str = 'text/plain') -> None:
|
||||
if isinstance(data, str):
|
||||
data = data.encode('ascii')
|
||||
if self.currently_writing_mime and self.currently_writing_mime != mime:
|
||||
@@ -295,7 +295,7 @@ class WriteRequest:
|
||||
self.mime_map[self.currently_writing_mime] = MimePos(start, self.tempfile.tell() - start)
|
||||
self.currently_writing_mime = ''
|
||||
|
||||
def write_base64_data(self, b: bytes) -> None:
|
||||
def write_base64_data(self, b: bytes | memoryview) -> None:
|
||||
if not self.max_size_exceeded:
|
||||
try:
|
||||
decoded = self.decoder.decode(b)
|
||||
|
||||
@@ -1418,7 +1418,7 @@ class ChildMonitor:
|
||||
def resize_pty(self, window_id: int, rows: int, cols: int, x_pixels: int, y_pixels: int) -> None:
|
||||
pass
|
||||
|
||||
def needs_write(self, child_id: int, data: bytes) -> bool:
|
||||
def needs_write(self, child_id: int, data: bytes | memoryview) -> bool:
|
||||
pass
|
||||
|
||||
def set_iutf8_winid(self, win_id: int, on: bool) -> bool:
|
||||
|
||||
@@ -244,8 +244,8 @@ def name_to_serialized_map() -> dict[str, str]:
|
||||
|
||||
|
||||
@run_once
|
||||
def serialized_to_field_map() -> dict[bytes, 'Field[Any]']:
|
||||
ans: dict[bytes, 'Field[Any]'] = {}
|
||||
def serialized_to_field_map() -> dict[bytes | memoryview, 'Field[Any]']:
|
||||
ans: dict[bytes | memoryview, 'Field[Any]'] = {}
|
||||
for k in fields(FileTransmissionCommand):
|
||||
ans[k.metadata.get('sname', k.name).encode('ascii')] = k
|
||||
return ans
|
||||
@@ -268,7 +268,7 @@ class FileTransmissionCommand:
|
||||
name: str = field(default='', metadata={'base64': True, 'sname': 'n'})
|
||||
status: str = field(default='', metadata={'base64': True, 'sname': 'st'})
|
||||
parent: str = field(default='', metadata={'sname': 'pr'})
|
||||
data: bytes = field(default=b'', repr=False, metadata={'sname': 'd'})
|
||||
data: bytes | memoryview = field(default=b'', repr=False, metadata={'sname': 'd'})
|
||||
|
||||
def __repr__(self) -> str:
|
||||
ans = []
|
||||
@@ -313,7 +313,7 @@ class FileTransmissionCommand:
|
||||
yield '='
|
||||
if inspect.isclass(k.type) and issubclass(k.type, Enum):
|
||||
yield val.name
|
||||
elif k.type is bytes:
|
||||
elif k.type == bytes | memoryview:
|
||||
yield base64_encode(val)
|
||||
elif k.type is str:
|
||||
if k.metadata.get('base64'):
|
||||
@@ -340,7 +340,7 @@ class FileTransmissionCommand:
|
||||
return
|
||||
if inspect.isclass(field.type) and issubclass(field.type, Enum):
|
||||
setattr(ans, field.name, field.type[str(val, "utf-8")])
|
||||
elif field.type is bytes:
|
||||
elif field.type == bytes | memoryview:
|
||||
setattr(ans, field.name, base64_decode(val))
|
||||
elif field.type is int:
|
||||
setattr(ans, field.name, int(val))
|
||||
@@ -360,8 +360,8 @@ class FileTransmissionCommand:
|
||||
|
||||
class IdentityDecompressor:
|
||||
|
||||
def __call__(self, data: bytes, is_last: bool = False) -> bytes:
|
||||
return data
|
||||
def __call__(self, data: bytes | memoryview, is_last: bool = False) -> bytes:
|
||||
return bytes(data)
|
||||
|
||||
|
||||
class ZlibDecompressor:
|
||||
@@ -370,7 +370,7 @@ class ZlibDecompressor:
|
||||
import zlib
|
||||
self.d = zlib.decompressobj(wbits=0)
|
||||
|
||||
def __call__(self, data: bytes, is_last: bool = False) -> bytes:
|
||||
def __call__(self, data: bytes | memoryview, is_last: bool = False) -> bytes:
|
||||
ans = self.d.decompress(data)
|
||||
if is_last:
|
||||
ans += self.d.flush()
|
||||
@@ -510,7 +510,7 @@ class DestFile:
|
||||
self.existing_stat = None
|
||||
self.needs_unlink = False
|
||||
|
||||
def write_data(self, all_files: dict[str, 'DestFile'], data: bytes, is_last: bool) -> None:
|
||||
def write_data(self, all_files: dict[str, 'DestFile'], data: bytes | memoryview, is_last: bool) -> None:
|
||||
if self.ftype is FileType.directory:
|
||||
raise TransmissionError(code=ErrorCode.EISDIR, file_id=self.file_id, msg='Cannot write data to a directory entry')
|
||||
if self.closed:
|
||||
@@ -687,6 +687,7 @@ class SourceFile:
|
||||
self.differ = None
|
||||
|
||||
def next_chunk(self, sz: int = 1024 * 1024) -> tuple[bytes, int]:
|
||||
data: bytes | memoryview = b''
|
||||
if self.target:
|
||||
self.transmitted = True
|
||||
data = self.target
|
||||
|
||||
@@ -1032,7 +1032,7 @@ class Window:
|
||||
text = ''.join(strings)
|
||||
get_boss().display_scrollback(self, text, title='Dump of lines', report_cursor=False)
|
||||
|
||||
def write_to_child(self, data: str | bytes) -> None:
|
||||
def write_to_child(self, data: str | bytes | memoryview) -> None:
|
||||
if data:
|
||||
if isinstance(data, str):
|
||||
data = data.encode('utf-8')
|
||||
|
||||
Reference in New Issue
Block a user