diff --git a/common/protob/pb2py b/common/protob/pb2py index aab8cc86a..d2c7f92d4 100755 --- a/common/protob/pb2py +++ b/common/protob/pb2py @@ -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] diff --git a/pyproject.toml b/pyproject.toml index 3774de16c..2029d36bc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,7 +67,6 @@ setuptools = ">=24.2.0" # storage cryptography = "*" hypothesis = "*" -attrs = "*" inotify = "*" yamllint = "^1.25.0" diff --git a/python/requirements.txt b/python/requirements.txt index 9b4ffe82e..191186e85 100644 --- a/python/requirements.txt +++ b/python/requirements.txt @@ -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' diff --git a/python/setup.cfg b/python/setup.cfg index 86c820791..5dcfcaacb 100644 --- a/python/setup.cfg +++ b/python/setup.cfg @@ -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 diff --git a/python/setup.py b/python/setup.py index 0c030a05f..0e6af3b9d 100755 --- a/python/setup.py +++ b/python/setup.py @@ -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 = { diff --git a/python/src/trezorlib/protobuf.py b/python/src/trezorlib/protobuf.py index e2dd2aa71..e50b6e140 100644 --- a/python/src/trezorlib/protobuf.py +++ b/python/src/trezorlib/protobuf.py @@ -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: diff --git a/python/src/trezorlib/toif.py b/python/src/trezorlib/toif.py index 49ff8f810..9db615838 100644 --- a/python/src/trezorlib/toif.py +++ b/python/src/trezorlib/toif.py @@ -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