From bf3e096735ca7be75d6c7203f55f8cbe7ef45b43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hozza?= Date: Tue, 11 Apr 2023 14:38:49 +0200 Subject: [PATCH] Fix errors reported by new version of mypy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix the following errors: ``` osbuild/util/lvm2.py:117: error: Only instance methods can be decorated with @property osbuild/api.py:50: error: Only instance methods can be decorated with @property osbuild/sources.py:85: error: Only instance methods can be decorated with @property ``` Chaining of `@classmethod` and `@property` has been deprecated since Python 3.11 with a note that chaining didn't work correctly in some cases. Relevant links: https://github.com/python/mypy/issues/13746 https://docs.python.org/3.11/whatsnew/3.11.html#language-builtins Signed-off-by: Tomáš Hozza --- osbuild/api.py | 11 ++++------- osbuild/sources.py | 12 ++++-------- osbuild/util/lvm2.py | 10 +++------- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/osbuild/api.py b/osbuild/api.py index 40daf8f6..08880136 100644 --- a/osbuild/api.py +++ b/osbuild/api.py @@ -8,7 +8,7 @@ import sys import tempfile import threading import traceback -from typing import Dict, Optional +from typing import ClassVar, Dict, Optional from .util import jsoncomm from .util.types import PathLike @@ -40,6 +40,9 @@ class BaseAPI(abc.ABC): call `_message.` """ + endpoint: ClassVar[str] + """The name of the API endpoint""" + def __init__(self, socket_address: Optional[PathLike] = None): self.socket_address = socket_address self.barrier = threading.Barrier(2) @@ -47,12 +50,6 @@ class BaseAPI(abc.ABC): self.thread = None self._socketdir = None - @property - @classmethod - @abc.abstractmethod - def endpoint(cls): - """The name of the API endpoint""" - @abc.abstractmethod def _message(self, msg: Dict, fds: jsoncomm.FdSet, sock: jsoncomm.Socket): """Called for a new incoming message diff --git a/osbuild/sources.py b/osbuild/sources.py index 7d2c43f4..fadb58d4 100644 --- a/osbuild/sources.py +++ b/osbuild/sources.py @@ -4,8 +4,7 @@ import contextlib import json import os import tempfile -from abc import abstractmethod -from typing import Dict, Tuple +from typing import ClassVar, Dict, Tuple from . import host from .objectstore import ObjectStore @@ -55,6 +54,9 @@ class SourceService(host.Service): max_workers = 1 + content_type: ClassVar[str] + """The content type of the source.""" + def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.cache = None @@ -82,12 +84,6 @@ class SourceService(host.Service): for _ in executor.map(self.fetch_one, *zip(*transformed)): pass - @property - @classmethod - @abstractmethod - def content_type(cls): - """The content type of the source.""" - @staticmethod def load_items(fds): with os.fdopen(fds.steal(0)) as f: diff --git a/osbuild/util/lvm2.py b/osbuild/util/lvm2.py index 11414051..05677230 100644 --- a/osbuild/util/lvm2.py +++ b/osbuild/util/lvm2.py @@ -18,7 +18,6 @@ LVM2 sources[1], specifically: [1] https://github.com/lvmteam/lvm2 (commit 8801a86) """ -import abc import binascii import io import json @@ -27,7 +26,7 @@ import re import struct import sys from collections import OrderedDict -from typing import BinaryIO, Dict, List, Union +from typing import BinaryIO, ClassVar, Dict, List, Union PathLike = Union[str, bytes, os.PathLike] @@ -114,11 +113,8 @@ class CStruct: class Header: """Abstract base class for all headers""" - @property - @classmethod - @abc.abstractmethod - def struct(cls) -> Union[struct.Struct, CStruct]: - """Definition of the underlying struct data""" + struct: ClassVar[Union[struct.Struct, CStruct]] + """Definition of the underlying struct data""" def __init__(self, data): self.data = data