Make mypy 1.16 happy
This commit is contained in:
parent
27fdfe6480
commit
62580c855b
10 changed files with 30 additions and 28 deletions
|
|
@ -50,7 +50,7 @@ def write(self, x: bytes | str) -> None:
|
||||||
|
|
||||||
screen = Screen(None, rows, columns, scrollback, cell_width, cell_height, 0, ToChild())
|
screen = Screen(None, rows, columns, scrollback, cell_width, cell_height, 0, ToChild())
|
||||||
|
|
||||||
def parse_bytes(data: bytes) -> None:
|
def parse_bytes(data: bytes|memoryview) -> None:
|
||||||
data = memoryview(data)
|
data = memoryview(data)
|
||||||
while data:
|
while data:
|
||||||
dest = screen.test_create_write_buffer()
|
dest = screen.test_create_write_buffer()
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ def __init__(self) -> None:
|
||||||
def query_code(self) -> str:
|
def query_code(self) -> str:
|
||||||
return f"\x1bP+q{self.encoded_query_name}\x1b\\"
|
return f"\x1bP+q{self.encoded_query_name}\x1b\\"
|
||||||
|
|
||||||
def decode_response(self, res: bytes) -> str:
|
def decode_response(self, res: bytes | memoryview) -> str:
|
||||||
return unhexlify(res).decode('utf-8')
|
return unhexlify(res).decode('utf-8')
|
||||||
|
|
||||||
def more_needed(self, buffer: bytes) -> bool:
|
def more_needed(self, buffer: bytes) -> bool:
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ def read_data_from_shared_memory(shm_name: str) -> Any:
|
||||||
return json.loads(shm.read_data_with_size())
|
return json.loads(shm.read_data_with_size())
|
||||||
|
|
||||||
|
|
||||||
def get_ssh_data(msgb: memoryview, request_id: str) -> Iterator[bytes]:
|
def get_ssh_data(msgb: memoryview, request_id: str) -> Iterator[bytes|memoryview]:
|
||||||
from base64 import standard_b64decode
|
from base64 import standard_b64decode
|
||||||
yield b'\nKITTY_DATA_START\n' # to discard leading data
|
yield b'\nKITTY_DATA_START\n' # to discard leading data
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,8 @@ def set_paths(cwd: str = '', home: str = '') -> Generator[None, None, None]:
|
||||||
|
|
||||||
class IdentityCompressor:
|
class IdentityCompressor:
|
||||||
|
|
||||||
def compress(self, data: bytes) -> bytes:
|
def compress(self, data: bytes | memoryview) -> bytes:
|
||||||
return data
|
return bytes(data)
|
||||||
|
|
||||||
def flush(self) -> bytes:
|
def flush(self) -> bytes:
|
||||||
return b''
|
return b''
|
||||||
|
|
@ -53,7 +53,7 @@ def __init__(self) -> None:
|
||||||
import zlib
|
import zlib
|
||||||
self.c = zlib.compressobj()
|
self.c = zlib.compressobj()
|
||||||
|
|
||||||
def compress(self, data: bytes) -> bytes:
|
def compress(self, data: bytes | memoryview) -> bytes:
|
||||||
return self.c.compress(data)
|
return self.c.compress(data)
|
||||||
|
|
||||||
def flush(self) -> bytes:
|
def flush(self) -> bytes:
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
from kitty.conf.utils import positive_float, positive_int
|
from kitty.conf.utils import positive_float, positive_int
|
||||||
from kitty.fast_data_types import create_canvas
|
from kitty.fast_data_types import create_canvas
|
||||||
from kitty.typing_compat import GRT_C, CompletedProcess, GRT_a, GRT_d, GRT_f, GRT_m, GRT_o, GRT_t, HandlerType
|
from kitty.typing_compat import CompletedProcess, GRT_f, GRT_o, HandlerType
|
||||||
from kitty.utils import ScreenSize, fit_image, which
|
from kitty.utils import ScreenSize, fit_image, which
|
||||||
|
|
||||||
from .operations import cursor
|
from .operations import cursor
|
||||||
|
|
@ -344,10 +344,10 @@ def __set_name__(self, owner: type['GraphicsCommand'], name: str) -> None:
|
||||||
|
|
||||||
|
|
||||||
class GraphicsCommand:
|
class GraphicsCommand:
|
||||||
a = action = Alias(cast(GRT_a, 't'))
|
a = action = Alias('t')
|
||||||
q = quiet = Alias(0)
|
q = quiet = Alias(0)
|
||||||
f = format = Alias(32)
|
f = format = Alias(32)
|
||||||
t = transmission_type = Alias(cast(GRT_t, 'd'))
|
t = transmission_type = Alias('d')
|
||||||
s = data_width = animation_state = Alias(0)
|
s = data_width = animation_state = Alias(0)
|
||||||
v = data_height = loop_count = Alias(0)
|
v = data_height = loop_count = Alias(0)
|
||||||
S = data_size = Alias(0)
|
S = data_size = Alias(0)
|
||||||
|
|
@ -356,7 +356,7 @@ class GraphicsCommand:
|
||||||
I = image_number = Alias(0) # noqa
|
I = image_number = Alias(0) # noqa
|
||||||
p = placement_id = Alias(0)
|
p = placement_id = Alias(0)
|
||||||
o = compression = Alias(cast(Optional[GRT_o], None))
|
o = compression = Alias(cast(Optional[GRT_o], None))
|
||||||
m = more = Alias(cast(GRT_m, 0))
|
m = more = Alias(0)
|
||||||
x = left_edge = Alias(0)
|
x = left_edge = Alias(0)
|
||||||
y = top_edge = Alias(0)
|
y = top_edge = Alias(0)
|
||||||
w = width = Alias(0)
|
w = width = Alias(0)
|
||||||
|
|
@ -366,8 +366,8 @@ class GraphicsCommand:
|
||||||
c = columns = other_frame_number = dest_frame = Alias(0)
|
c = columns = other_frame_number = dest_frame = Alias(0)
|
||||||
r = rows = frame_number = source_frame = Alias(0)
|
r = rows = frame_number = source_frame = Alias(0)
|
||||||
z = z_index = gap = Alias(0)
|
z = z_index = gap = Alias(0)
|
||||||
C = cursor_movement = compose_mode = Alias(cast(GRT_C, 0))
|
C = cursor_movement = compose_mode = Alias(0)
|
||||||
d = delete_action = Alias(cast(GRT_d, 'a'))
|
d = delete_action = Alias('a')
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self._actual_values: dict[str, Any] = {}
|
self._actual_values: dict[str, Any] = {}
|
||||||
|
|
@ -380,12 +380,12 @@ def clone(self) -> 'GraphicsCommand':
|
||||||
ans._actual_values = self._actual_values.copy()
|
ans._actual_values = self._actual_values.copy()
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
def serialize(self, payload: bytes | str = b'') -> bytes:
|
def serialize(self, payload: bytes | memoryview | str = b'') -> bytes:
|
||||||
items = []
|
items = []
|
||||||
for k, val in self._actual_values.items():
|
for k, val in self._actual_values.items():
|
||||||
items.append(f'{k}={val}')
|
items.append(f'{k}={val}')
|
||||||
|
|
||||||
ans: list[bytes] = []
|
ans: list[bytes|memoryview] = []
|
||||||
w = ans.append
|
w = ans.append
|
||||||
w(b'\033_G')
|
w(b'\033_G')
|
||||||
w(','.join(items).encode('ascii'))
|
w(','.join(items).encode('ascii'))
|
||||||
|
|
|
||||||
|
|
@ -212,7 +212,7 @@ class ReadRequest(NamedTuple):
|
||||||
id: str = ''
|
id: str = ''
|
||||||
protocol_type: ProtocolType = ProtocolType.osc_52
|
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}'
|
ans = f'{self.protocol_type.value};type=read:status={status}'
|
||||||
if status == 'OK' and self.is_primary_selection:
|
if status == 'OK' and self.is_primary_selection:
|
||||||
ans += ':loc=primary'
|
ans += ':loc=primary'
|
||||||
|
|
@ -276,7 +276,7 @@ def commit(self) -> None:
|
||||||
x = {mime: self.tempfile.create_chunker(pos.start, pos.size) for mime, pos in self.mime_map.items()}
|
x = {mime: self.tempfile.create_chunker(pos.start, pos.size) for mime, pos in self.mime_map.items()}
|
||||||
cp.set_mime(x)
|
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):
|
if isinstance(data, str):
|
||||||
data = data.encode('ascii')
|
data = data.encode('ascii')
|
||||||
if self.currently_writing_mime and self.currently_writing_mime != mime:
|
if self.currently_writing_mime and self.currently_writing_mime != mime:
|
||||||
|
|
@ -295,7 +295,7 @@ def flush_base64_data(self) -> None:
|
||||||
self.mime_map[self.currently_writing_mime] = MimePos(start, self.tempfile.tell() - start)
|
self.mime_map[self.currently_writing_mime] = MimePos(start, self.tempfile.tell() - start)
|
||||||
self.currently_writing_mime = ''
|
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:
|
if not self.max_size_exceeded:
|
||||||
try:
|
try:
|
||||||
decoded = self.decoder.decode(b)
|
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:
|
def resize_pty(self, window_id: int, rows: int, cols: int, x_pixels: int, y_pixels: int) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def needs_write(self, child_id: int, data: bytes) -> bool:
|
def needs_write(self, child_id: int, data: bytes | memoryview) -> bool:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def set_iutf8_winid(self, win_id: int, on: bool) -> bool:
|
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
|
@run_once
|
||||||
def serialized_to_field_map() -> dict[bytes, 'Field[Any]']:
|
def serialized_to_field_map() -> dict[bytes | memoryview, 'Field[Any]']:
|
||||||
ans: dict[bytes, 'Field[Any]'] = {}
|
ans: dict[bytes | memoryview, 'Field[Any]'] = {}
|
||||||
for k in fields(FileTransmissionCommand):
|
for k in fields(FileTransmissionCommand):
|
||||||
ans[k.metadata.get('sname', k.name).encode('ascii')] = k
|
ans[k.metadata.get('sname', k.name).encode('ascii')] = k
|
||||||
return ans
|
return ans
|
||||||
|
|
@ -268,7 +268,7 @@ class FileTransmissionCommand:
|
||||||
name: str = field(default='', metadata={'base64': True, 'sname': 'n'})
|
name: str = field(default='', metadata={'base64': True, 'sname': 'n'})
|
||||||
status: str = field(default='', metadata={'base64': True, 'sname': 'st'})
|
status: str = field(default='', metadata={'base64': True, 'sname': 'st'})
|
||||||
parent: str = field(default='', metadata={'sname': 'pr'})
|
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:
|
def __repr__(self) -> str:
|
||||||
ans = []
|
ans = []
|
||||||
|
|
@ -313,7 +313,7 @@ def get_serialized_fields(self, prefix_with_osc_code: bool = False) -> Iterator[
|
||||||
yield '='
|
yield '='
|
||||||
if inspect.isclass(k.type) and issubclass(k.type, Enum):
|
if inspect.isclass(k.type) and issubclass(k.type, Enum):
|
||||||
yield val.name
|
yield val.name
|
||||||
elif k.type is bytes:
|
elif k.type == bytes | memoryview:
|
||||||
yield base64_encode(val)
|
yield base64_encode(val)
|
||||||
elif k.type is str:
|
elif k.type is str:
|
||||||
if k.metadata.get('base64'):
|
if k.metadata.get('base64'):
|
||||||
|
|
@ -340,7 +340,7 @@ def handle_item(key: memoryview, val: memoryview) -> None:
|
||||||
return
|
return
|
||||||
if inspect.isclass(field.type) and issubclass(field.type, Enum):
|
if inspect.isclass(field.type) and issubclass(field.type, Enum):
|
||||||
setattr(ans, field.name, field.type[str(val, "utf-8")])
|
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))
|
setattr(ans, field.name, base64_decode(val))
|
||||||
elif field.type is int:
|
elif field.type is int:
|
||||||
setattr(ans, field.name, int(val))
|
setattr(ans, field.name, int(val))
|
||||||
|
|
@ -360,8 +360,8 @@ def handle_item(key: memoryview, val: memoryview) -> None:
|
||||||
|
|
||||||
class IdentityDecompressor:
|
class IdentityDecompressor:
|
||||||
|
|
||||||
def __call__(self, data: bytes, is_last: bool = False) -> bytes:
|
def __call__(self, data: bytes | memoryview, is_last: bool = False) -> bytes:
|
||||||
return data
|
return bytes(data)
|
||||||
|
|
||||||
|
|
||||||
class ZlibDecompressor:
|
class ZlibDecompressor:
|
||||||
|
|
@ -370,7 +370,7 @@ def __init__(self) -> None:
|
||||||
import zlib
|
import zlib
|
||||||
self.d = zlib.decompressobj(wbits=0)
|
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)
|
ans = self.d.decompress(data)
|
||||||
if is_last:
|
if is_last:
|
||||||
ans += self.d.flush()
|
ans += self.d.flush()
|
||||||
|
|
@ -510,7 +510,7 @@ def unlink_existing_if_needed(self, force: bool = False) -> None:
|
||||||
self.existing_stat = None
|
self.existing_stat = None
|
||||||
self.needs_unlink = False
|
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:
|
if self.ftype is FileType.directory:
|
||||||
raise TransmissionError(code=ErrorCode.EISDIR, file_id=self.file_id, msg='Cannot write data to a directory entry')
|
raise TransmissionError(code=ErrorCode.EISDIR, file_id=self.file_id, msg='Cannot write data to a directory entry')
|
||||||
if self.closed:
|
if self.closed:
|
||||||
|
|
@ -687,6 +687,7 @@ def close(self) -> None:
|
||||||
self.differ = None
|
self.differ = None
|
||||||
|
|
||||||
def next_chunk(self, sz: int = 1024 * 1024) -> tuple[bytes, int]:
|
def next_chunk(self, sz: int = 1024 * 1024) -> tuple[bytes, int]:
|
||||||
|
data: bytes | memoryview = b''
|
||||||
if self.target:
|
if self.target:
|
||||||
self.transmitted = True
|
self.transmitted = True
|
||||||
data = self.target
|
data = self.target
|
||||||
|
|
|
||||||
|
|
@ -1032,7 +1032,7 @@ def dump_lines_with_attrs(self, which_screen: Literal['main', 'alternate', 'curr
|
||||||
text = ''.join(strings)
|
text = ''.join(strings)
|
||||||
get_boss().display_scrollback(self, text, title='Dump of lines', report_cursor=False)
|
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 data:
|
||||||
if isinstance(data, str):
|
if isinstance(data, str):
|
||||||
data = data.encode('utf-8')
|
data = data.encode('utf-8')
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ disallow_untyped_decorators = true
|
||||||
disallow_untyped_calls = true
|
disallow_untyped_calls = true
|
||||||
disallow_incomplete_defs = true
|
disallow_incomplete_defs = true
|
||||||
strict = true
|
strict = true
|
||||||
|
strict_bytes = true
|
||||||
no_implicit_reexport = true
|
no_implicit_reexport = true
|
||||||
|
|
||||||
[tool.pylsp-mypy]
|
[tool.pylsp-mypy]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue