From 0728b35735362b5b60301c36781b6a030aa161fb Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sun, 12 Jan 2025 22:23:20 +0100 Subject: [PATCH] Drop the custom data class decorator for now, since it is not performance relevant --- novelwriter/formats/shared.py | 3 --- novelwriter/gui/theme.py | 4 +--- novelwriter/types.py | 29 ----------------------------- 3 files changed, 1 insertion(+), 35 deletions(-) diff --git a/novelwriter/formats/shared.py b/novelwriter/formats/shared.py index fecafea9..549f6f19 100644 --- a/novelwriter/formats/shared.py +++ b/novelwriter/formats/shared.py @@ -29,8 +29,6 @@ from enum import Flag, IntEnum from PyQt6.QtGui import QColor -from novelwriter.types import nwDataClass - ESCAPES = {r"\*": "*", r"\~": "~", r"\_": "_", r"\[": "[", r"\]": "]", r"\ ": ""} RX_ESC = re.compile("|".join([re.escape(k) for k in ESCAPES.keys()]), flags=re.DOTALL) @@ -42,7 +40,6 @@ def stripEscape(text: str) -> str: return text -@nwDataClass class TextDocumentTheme: """Default document theme.""" diff --git a/novelwriter/gui/theme.py b/novelwriter/gui/theme.py index 9c583a80..3f85e2c1 100644 --- a/novelwriter/gui/theme.py +++ b/novelwriter/gui/theme.py @@ -41,7 +41,7 @@ from novelwriter.common import NWConfigParser, cssCol, minmax from novelwriter.constants import nwLabels from novelwriter.enum import nwItemClass, nwItemLayout, nwItemType from novelwriter.error import logException -from novelwriter.types import QtPaintAntiAlias, QtTransparent, nwDataClass +from novelwriter.types import QtPaintAntiAlias, QtTransparent logger = logging.getLogger(__name__) @@ -50,7 +50,6 @@ STYLES_MIN_TOOLBUTTON = "minimalToolButton" STYLES_BIG_TOOLBUTTON = "bigToolButton" -@nwDataClass class ThemeMeta: name: str = "" @@ -62,7 +61,6 @@ class ThemeMeta: licenseUrl: str = "" -@nwDataClass class SyntaxColors: back: QColor = QColor(255, 255, 255) diff --git a/novelwriter/types.py b/novelwriter/types.py index e06177b7..e1b05ead 100644 --- a/novelwriter/types.py +++ b/novelwriter/types.py @@ -23,8 +23,6 @@ along with this program. If not, see . """ from __future__ import annotations -from typing import Any, TypeVar - from PyQt6.QtCore import Qt from PyQt6.QtGui import QColor, QFont, QPainter, QTextCharFormat, QTextCursor, QTextFormat from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QHeaderView, QSizePolicy, QStyle @@ -148,30 +146,3 @@ FONT_STYLE: dict[QFont.Style, str] = { QFont.Style.StyleItalic: "italic", QFont.Style.StyleOblique: "oblique", } - -## -# Decorators and MetaClasses -## - -T_ = TypeVar("T_", bound=object) - - -def nwDataClass(cls: T_) -> T_: - """A simple data class decorator that generates slots automatically - and creates an init function to match. - """ - - def wrap(cls: T_) -> T_: - fields = tuple(a for a in dir(cls) if not a.startswith("__")) - values = {a: getattr(cls, a) for a in fields} - - def init(self: Any) -> None: - nonlocal values - for a, v in values.items(): - self.__setattr__(a, v) - - return type(cls.__class__.__name__, (object,), { # type: ignore - "__slots__": fields, "__init__": init - }) - - return wrap(cls)