diff --git a/boxes/__init__.py b/boxes/__init__.py index a7ded43..1ac1528 100755 --- a/boxes/__init__.py +++ b/boxes/__init__.py @@ -13,6 +13,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from __future__ import annotations import argparse import copy @@ -24,7 +25,7 @@ from argparse import ArgumentParser from contextlib import contextmanager from functools import wraps from shlex import quote -from typing import Optional, List +from typing import Any from xml.sax.saxutils import quoteattr from shapely.geometry import * @@ -179,9 +180,9 @@ class ArgparseEdgeType: """argparse type to select from a set of edge types""" names = edges.getDescriptions() - edges: List[str] = [] + edges: list[str] = [] - def __init__(self, edges: Optional[str] = None) -> None: + def __init__(self, edges: str | None = None) -> None: if edges: self.edges = list(edges) @@ -282,16 +283,16 @@ class Boxes: webinterface = True ui_group = "Misc" - description = "" # Markdown syntax is supported + description: str = "" # Markdown syntax is supported def __init__(self) -> None: self.formats = formats.Formats() self.ctx = None - description = self.__doc__ + description: str = self.__doc__ or "" if self.description: description += "\n\n" + self.description self.argparser = ArgumentParser(description=description) - self.edgesettings = {} + self.edgesettings: dict[Any, Any] = {} self.inkscapefile = None self.metadata = { diff --git a/boxes/drawing.py b/boxes/drawing.py index 0c57b5a..f205a0e 100644 --- a/boxes/drawing.py +++ b/boxes/drawing.py @@ -1,5 +1,8 @@ +from __future__ import annotations + import datetime import math +from typing import Any from xml.etree import ElementTree as ET from affine import Affine @@ -29,7 +32,7 @@ class Surface: def __init__(self, fname) -> None: self._fname = fname - self.parts = [] + self.parts: list[Any] = [] self._p = self.new_part("default") def set_metadata(self, metadata): @@ -94,8 +97,8 @@ class Surface: class Part: def __init__(self, name) -> None: - self.pathes = [] - self.path = [] + self.pathes: list[Any] = [] + self.path: list[Any] = [] def extents(self): if not self.pathes: @@ -217,7 +220,7 @@ class Context: self._bounds = Extents() self._padding = PADDING - self._stack = [] + self._stack: list[Any] = [] self._m = Affine.translation(0, 0) self._xy = (0, 0) self._mxy = self._m * self._xy diff --git a/boxes/generators/__init__.py b/boxes/generators/__init__.py index a156a28..2c56ab0 100644 --- a/boxes/generators/__init__.py +++ b/boxes/generators/__init__.py @@ -1,6 +1,9 @@ +from __future__ import annotations + import importlib import inspect import pkgutil +from typing import Any import boxes @@ -13,7 +16,7 @@ class UIGroup: self.title = title or name self.description = description self._image = image - self.generators = [] + self.generators: list[Any] = [] # register ui_groups_by_name[name] = self diff --git a/boxes/generators/_swtemplate.py b/boxes/generators/_swtemplate.py index 320e329..df42c26 100644 --- a/boxes/generators/_swtemplate.py +++ b/boxes/generators/_swtemplate.py @@ -14,6 +14,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +# mypy: ignore-errors + from boxes import * class SlatwallXXX(Boxes): # Change class name! diff --git a/boxes/generators/dividertray.py b/boxes/generators/dividertray.py index ea11636..857405c 100644 --- a/boxes/generators/dividertray.py +++ b/boxes/generators/dividertray.py @@ -14,6 +14,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from __future__ import annotations + import math from functools import partial @@ -366,9 +368,9 @@ You will likely need to cut each of the dividers you want multiple times. class SlottedEdgeDescriptions: def __init__(self) -> None: - self.descriptions = [] + self.descriptions: list[str] = [] - def add(self, description): + def add(self, description: str) -> None: self.descriptions.append(description) def get_straigth_edges(self): diff --git a/scripts/boxes2pot b/scripts/boxes2pot index 6583683..0453926 100755 --- a/scripts/boxes2pot +++ b/scripts/boxes2pot @@ -13,10 +13,12 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from __future__ import annotations import argparse import os.path import sys +from typing import Any try: import boxes.generators @@ -40,8 +42,8 @@ class DefaultParams(boxes.Boxes): class Boxes2pot: def __init__(self) -> None: - self.messages = [] - self.message_set = set() + self.messages: list[Any] = [] + self.message_set: set[Any] = set() self.boxes = {b.__name__ : b() for b in boxes.generators.getAllBoxGenerators().values() if b.webinterface} self.groups = boxes.generators.ui_groups self.groups_by_name = boxes.generators.ui_groups_by_name diff --git a/scripts/boxesserver b/scripts/boxesserver index 154553a..367e10d 100755 --- a/scripts/boxesserver +++ b/scripts/boxesserver @@ -13,6 +13,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . +from __future__ import annotations import argparse import gettext @@ -26,6 +27,7 @@ import tempfile import threading import time import traceback +from typing import Any from urllib.parse import parse_qs from urllib.parse import unquote_plus, quote from wsgiref.simple_server import make_server @@ -94,7 +96,7 @@ class BServer: def __init__(self) -> None: self.boxes = {b.__name__ : b for b in boxes.generators.getAllBoxGenerators().values() if b.webinterface} - self.boxes['TrayLayout2'] = boxes.generators.traylayout.TrayLayout2 + self.boxes['TrayLayout2'] = boxes.generators.traylayout.TrayLayout2 # type: ignore # no attribute "traylayout" self.groups = boxes.generators.ui_groups self.groups_by_name = boxes.generators.ui_groups_by_name @@ -104,7 +106,7 @@ class BServer: self.staticdir = os.path.join(os.path.dirname(__file__), '../static/') self._languages = None - self._cache = {} + self._cache: dict[Any, Any] = {} def getLanguages(self, domain=None, localedir=None): if self._languages is not None: