Add typing: variables

This commit is contained in:
Rotzbua 2023-01-08 19:41:02 +01:00 committed by Florian Festi
parent 11340448fa
commit fceb5f2dfe
7 changed files with 32 additions and 17 deletions

View File

@ -13,6 +13,7 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import annotations
import argparse import argparse
import copy import copy
@ -24,7 +25,7 @@ from argparse import ArgumentParser
from contextlib import contextmanager from contextlib import contextmanager
from functools import wraps from functools import wraps
from shlex import quote from shlex import quote
from typing import Optional, List from typing import Any
from xml.sax.saxutils import quoteattr from xml.sax.saxutils import quoteattr
from shapely.geometry import * from shapely.geometry import *
@ -179,9 +180,9 @@ class ArgparseEdgeType:
"""argparse type to select from a set of edge types""" """argparse type to select from a set of edge types"""
names = edges.getDescriptions() 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: if edges:
self.edges = list(edges) self.edges = list(edges)
@ -282,16 +283,16 @@ class Boxes:
webinterface = True webinterface = True
ui_group = "Misc" ui_group = "Misc"
description = "" # Markdown syntax is supported description: str = "" # Markdown syntax is supported
def __init__(self) -> None: def __init__(self) -> None:
self.formats = formats.Formats() self.formats = formats.Formats()
self.ctx = None self.ctx = None
description = self.__doc__ description: str = self.__doc__ or ""
if self.description: if self.description:
description += "\n\n" + self.description description += "\n\n" + self.description
self.argparser = ArgumentParser(description=description) self.argparser = ArgumentParser(description=description)
self.edgesettings = {} self.edgesettings: dict[Any, Any] = {}
self.inkscapefile = None self.inkscapefile = None
self.metadata = { self.metadata = {

View File

@ -1,5 +1,8 @@
from __future__ import annotations
import datetime import datetime
import math import math
from typing import Any
from xml.etree import ElementTree as ET from xml.etree import ElementTree as ET
from affine import Affine from affine import Affine
@ -29,7 +32,7 @@ class Surface:
def __init__(self, fname) -> None: def __init__(self, fname) -> None:
self._fname = fname self._fname = fname
self.parts = [] self.parts: list[Any] = []
self._p = self.new_part("default") self._p = self.new_part("default")
def set_metadata(self, metadata): def set_metadata(self, metadata):
@ -94,8 +97,8 @@ class Surface:
class Part: class Part:
def __init__(self, name) -> None: def __init__(self, name) -> None:
self.pathes = [] self.pathes: list[Any] = []
self.path = [] self.path: list[Any] = []
def extents(self): def extents(self):
if not self.pathes: if not self.pathes:
@ -217,7 +220,7 @@ class Context:
self._bounds = Extents() self._bounds = Extents()
self._padding = PADDING self._padding = PADDING
self._stack = [] self._stack: list[Any] = []
self._m = Affine.translation(0, 0) self._m = Affine.translation(0, 0)
self._xy = (0, 0) self._xy = (0, 0)
self._mxy = self._m * self._xy self._mxy = self._m * self._xy

View File

@ -1,6 +1,9 @@
from __future__ import annotations
import importlib import importlib
import inspect import inspect
import pkgutil import pkgutil
from typing import Any
import boxes import boxes
@ -13,7 +16,7 @@ class UIGroup:
self.title = title or name self.title = title or name
self.description = description self.description = description
self._image = image self._image = image
self.generators = [] self.generators: list[Any] = []
# register # register
ui_groups_by_name[name] = self ui_groups_by_name[name] = self

View File

@ -14,6 +14,8 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# mypy: ignore-errors
from boxes import * from boxes import *
class SlatwallXXX(Boxes): # Change class name! class SlatwallXXX(Boxes): # Change class name!

View File

@ -14,6 +14,8 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import annotations
import math import math
from functools import partial from functools import partial
@ -366,9 +368,9 @@ You will likely need to cut each of the dividers you want multiple times.
class SlottedEdgeDescriptions: class SlottedEdgeDescriptions:
def __init__(self) -> None: def __init__(self) -> None:
self.descriptions = [] self.descriptions: list[str] = []
def add(self, description): def add(self, description: str) -> None:
self.descriptions.append(description) self.descriptions.append(description)
def get_straigth_edges(self): def get_straigth_edges(self):

View File

@ -13,10 +13,12 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import annotations
import argparse import argparse
import os.path import os.path
import sys import sys
from typing import Any
try: try:
import boxes.generators import boxes.generators
@ -40,8 +42,8 @@ class DefaultParams(boxes.Boxes):
class Boxes2pot: class Boxes2pot:
def __init__(self) -> None: def __init__(self) -> None:
self.messages = [] self.messages: list[Any] = []
self.message_set = set() self.message_set: set[Any] = set()
self.boxes = {b.__name__ : b() for b in boxes.generators.getAllBoxGenerators().values() if b.webinterface} self.boxes = {b.__name__ : b() for b in boxes.generators.getAllBoxGenerators().values() if b.webinterface}
self.groups = boxes.generators.ui_groups self.groups = boxes.generators.ui_groups
self.groups_by_name = boxes.generators.ui_groups_by_name self.groups_by_name = boxes.generators.ui_groups_by_name

View File

@ -13,6 +13,7 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import annotations
import argparse import argparse
import gettext import gettext
@ -26,6 +27,7 @@ import tempfile
import threading import threading
import time import time
import traceback import traceback
from typing import Any
from urllib.parse import parse_qs from urllib.parse import parse_qs
from urllib.parse import unquote_plus, quote from urllib.parse import unquote_plus, quote
from wsgiref.simple_server import make_server from wsgiref.simple_server import make_server
@ -94,7 +96,7 @@ class BServer:
def __init__(self) -> None: def __init__(self) -> None:
self.boxes = {b.__name__ : b for b in boxes.generators.getAllBoxGenerators().values() if b.webinterface} 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 = boxes.generators.ui_groups
self.groups_by_name = boxes.generators.ui_groups_by_name 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.staticdir = os.path.join(os.path.dirname(__file__), '../static/')
self._languages = None self._languages = None
self._cache = {} self._cache: dict[Any, Any] = {}
def getLanguages(self, domain=None, localedir=None): def getLanguages(self, domain=None, localedir=None):
if self._languages is not None: if self._languages is not None: