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