Drop the custom data class decorator for now, since it is not performance relevant

This commit is contained in:
Veronica Berglyd Olsen
2025-01-12 22:23:20 +01:00
parent e7a0803ca4
commit 0728b35735
3 changed files with 1 additions and 35 deletions
-3
View File
@@ -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."""
+1 -3
View File
@@ -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)
-29
View File
@@ -23,8 +23,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
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)