mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 14:28:07 +00:00
chore(python): replacing attrs with dataclasses
This commit is contained in:
parent
57579c5a80
commit
77afcb335b
@ -10,16 +10,14 @@ import shutil
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
|
from dataclasses import dataclass
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
import attr
|
|
||||||
import click
|
import click
|
||||||
import construct as c
|
import construct as c
|
||||||
import mako
|
import mako
|
||||||
import mako.template
|
import mako.template
|
||||||
|
|
||||||
from google.protobuf import descriptor_pb2
|
from google.protobuf import descriptor_pb2
|
||||||
|
|
||||||
FieldDescriptor = descriptor_pb2.FieldDescriptorProto
|
FieldDescriptor = descriptor_pb2.FieldDescriptorProto
|
||||||
@ -140,7 +138,7 @@ QDEF_RE = re.compile(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@attr.s(auto_attribs=True)
|
@dataclass
|
||||||
class ProtoField:
|
class ProtoField:
|
||||||
name: str
|
name: str
|
||||||
number: int
|
number: int
|
||||||
@ -229,7 +227,7 @@ class ProtoField:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@attr.s(auto_attribs=True)
|
@dataclass
|
||||||
class ProtoMessage:
|
class ProtoMessage:
|
||||||
name: str
|
name: str
|
||||||
wire_type: Optional[int]
|
wire_type: Optional[int]
|
||||||
|
@ -67,7 +67,6 @@ setuptools = ">=24.2.0"
|
|||||||
# storage
|
# storage
|
||||||
cryptography = "*"
|
cryptography = "*"
|
||||||
hypothesis = "*"
|
hypothesis = "*"
|
||||||
attrs = "*"
|
|
||||||
inotify = "*"
|
inotify = "*"
|
||||||
yamllint = "^1.25.0"
|
yamllint = "^1.25.0"
|
||||||
|
|
||||||
|
@ -5,4 +5,4 @@ click>=7,<9
|
|||||||
libusb1>=1.6.4
|
libusb1>=1.6.4
|
||||||
construct>=2.9,!=2.10.55
|
construct>=2.9,!=2.10.55
|
||||||
typing_extensions>=3.7.4
|
typing_extensions>=3.7.4
|
||||||
attrs
|
dataclasses ; python_version<'3.7'
|
||||||
|
@ -25,7 +25,7 @@ per-file-ignores =
|
|||||||
helper-scripts/*:I
|
helper-scripts/*:I
|
||||||
tools/*:I
|
tools/*:I
|
||||||
tests/*:I
|
tests/*:I
|
||||||
known-modules = libusb1:[usb1],hidapi:[hid],attrs:[attr],PyQt5:[PyQt5.QtWidgets,PyQt5.QtGui,PyQt5.QtCore]
|
known-modules = libusb1:[usb1],hidapi:[hid],PyQt5:[PyQt5.QtWidgets,PyQt5.QtGui,PyQt5.QtCore]
|
||||||
|
|
||||||
[isort]
|
[isort]
|
||||||
multi_line_output = 3
|
multi_line_output = 3
|
||||||
|
@ -13,7 +13,7 @@ install_requires = [
|
|||||||
"libusb1>=1.6.4",
|
"libusb1>=1.6.4",
|
||||||
"construct>=2.9",
|
"construct>=2.9",
|
||||||
"typing_extensions>=3.7.4",
|
"typing_extensions>=3.7.4",
|
||||||
"attrs",
|
"dataclasses ; python_version<'3.7'",
|
||||||
]
|
]
|
||||||
|
|
||||||
extras_require = {
|
extras_require = {
|
||||||
|
@ -24,12 +24,12 @@ For serializing (dumping) protobuf types, object with `Writer` interface is requ
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import warnings
|
import warnings
|
||||||
|
from dataclasses import dataclass
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from itertools import zip_longest
|
from itertools import zip_longest
|
||||||
from typing import Any, Dict, List, Optional, Type, TypeVar, Union
|
from typing import Any, Dict, List, Optional, Type, TypeVar, Union
|
||||||
|
|
||||||
import attr
|
|
||||||
from typing_extensions import Protocol
|
from typing_extensions import Protocol
|
||||||
|
|
||||||
MT = TypeVar("MT", bound="MessageType")
|
MT = TypeVar("MT", bound="MessageType")
|
||||||
@ -141,13 +141,13 @@ WIRE_TYPES = {
|
|||||||
REQUIRED_FIELD_PLACEHOLDER = object()
|
REQUIRED_FIELD_PLACEHOLDER = object()
|
||||||
|
|
||||||
|
|
||||||
@attr.s(auto_attribs=True)
|
@dataclass
|
||||||
class Field:
|
class Field:
|
||||||
name: str
|
name: str
|
||||||
type: str
|
type: str
|
||||||
repeated: bool = attr.ib(default=False)
|
repeated: bool = False
|
||||||
required: bool = attr.ib(default=False)
|
required: bool = False
|
||||||
default: object = attr.ib(default=None)
|
default: object = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def wire_type(self) -> int:
|
def wire_type(self) -> int:
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import struct
|
import struct
|
||||||
import zlib
|
import zlib
|
||||||
|
from dataclasses import dataclass
|
||||||
from typing import Sequence, Tuple
|
from typing import Sequence, Tuple
|
||||||
|
|
||||||
import attr
|
|
||||||
|
|
||||||
from . import firmware
|
from . import firmware
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -61,14 +60,14 @@ def _to_grayscale(data: bytes) -> bytes:
|
|||||||
return bytes(res)
|
return bytes(res)
|
||||||
|
|
||||||
|
|
||||||
@attr.s
|
@dataclass
|
||||||
class Toif:
|
class Toif:
|
||||||
mode: firmware.ToifMode = attr.ib()
|
mode: firmware.ToifMode
|
||||||
size: Tuple[int, int] = attr.ib()
|
size: Tuple[int, int]
|
||||||
data: bytes = attr.ib()
|
data: bytes
|
||||||
|
|
||||||
@data.validator
|
def __post_init__(self) -> None:
|
||||||
def check_data_size(self, _, value):
|
# checking the data size
|
||||||
width, height = self.size
|
width, height = self.size
|
||||||
if self.mode is firmware.ToifMode.grayscale:
|
if self.mode is firmware.ToifMode.grayscale:
|
||||||
expected_size = width * height // 2
|
expected_size = width * height // 2
|
||||||
|
Loading…
Reference in New Issue
Block a user