执行 Ruff 安全自动修复
This commit is contained in:
+10
-10
@@ -9,9 +9,9 @@
|
||||
0x0c ZERO 0x0d SIMPLE_LIST
|
||||
"""
|
||||
|
||||
import struct
|
||||
import io
|
||||
from typing import Any, Dict, List, Optional, Tuple
|
||||
import struct
|
||||
from typing import Any
|
||||
|
||||
|
||||
class TafType:
|
||||
@@ -136,7 +136,7 @@ class TafOutputStream:
|
||||
|
||||
# ---- Map ----
|
||||
def write_map(
|
||||
self, tag: int, value: Dict[Any, Any], key_writer=None, val_writer=None
|
||||
self, tag: int, value: dict[Any, Any], key_writer=None, val_writer=None
|
||||
):
|
||||
self.write_head(tag, TafType.MAP)
|
||||
self.write_int32(0, len(value))
|
||||
@@ -151,7 +151,7 @@ class TafOutputStream:
|
||||
self._write_any(1, v)
|
||||
|
||||
# ---- List ----
|
||||
def write_list(self, tag: int, value: List[Any], item_writer=None):
|
||||
def write_list(self, tag: int, value: list[Any], item_writer=None):
|
||||
self.write_head(tag, TafType.LIST)
|
||||
self.write_int32(0, len(value))
|
||||
for item in value:
|
||||
@@ -192,7 +192,7 @@ class TafInputStream:
|
||||
def __init__(self, data: bytes):
|
||||
self.buf = io.BytesIO(data)
|
||||
|
||||
def peek_head(self) -> Tuple[int, int]:
|
||||
def peek_head(self) -> tuple[int, int]:
|
||||
"""读取 head 但不消费(用于探测)"""
|
||||
pos = self.buf.tell()
|
||||
try:
|
||||
@@ -200,7 +200,7 @@ class TafInputStream:
|
||||
finally:
|
||||
self.buf.seek(pos)
|
||||
|
||||
def read_head(self) -> Tuple[int, int]:
|
||||
def read_head(self) -> tuple[int, int]:
|
||||
"""返回 (tag, type)"""
|
||||
data = self.buf.read(1)
|
||||
if not data:
|
||||
@@ -293,7 +293,7 @@ class TafInputStream:
|
||||
self.skip_field(it)
|
||||
|
||||
# ---- 带跳过策略的字段读取:找到 tag,否则返回默认 ----
|
||||
def _find_tag(self, target_tag: int, required: bool) -> Optional[Tuple[int, int]]:
|
||||
def _find_tag(self, target_tag: int, required: bool) -> tuple[int, int] | None:
|
||||
"""逐个读 head,tag 相等则返回,tag 超过则回退并返回 None"""
|
||||
while True:
|
||||
pos = self.buf.tell()
|
||||
@@ -402,7 +402,7 @@ class TafInputStream:
|
||||
# ---- 复合类型 ----
|
||||
def read_map(
|
||||
self, tag: int, required: bool = False, key_reader=None, val_reader=None
|
||||
) -> Dict:
|
||||
) -> dict:
|
||||
found = self._find_tag(tag, required)
|
||||
if not found:
|
||||
return {}
|
||||
@@ -418,7 +418,7 @@ class TafInputStream:
|
||||
result[k] = v
|
||||
return result
|
||||
|
||||
def read_list(self, tag: int, required: bool = False, item_reader=None) -> List:
|
||||
def read_list(self, tag: int, required: bool = False, item_reader=None) -> list:
|
||||
found = self._find_tag(tag, required)
|
||||
if not found:
|
||||
return []
|
||||
@@ -486,7 +486,7 @@ class TafStruct:
|
||||
def read_from(self, ins: TafInputStream):
|
||||
raise NotImplementedError
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
def to_dict(self) -> dict[str, Any]:
|
||||
"""调试用:转字典"""
|
||||
return {k: v for k, v in self.__dict__.items() if not k.startswith("_")}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user