Skip to content

Commit

Permalink
attempt to fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
FriedrichFroebel committed Oct 28, 2023
1 parent ebf96ff commit 715801a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
11 changes: 9 additions & 2 deletions brother_ql_web/utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
from __future__ import annotations

import sys
from typing import cast

from brother_ql.backends import backend_factory, BrotherQLBackendGeneric, guess_backend
from brother_ql.devicedependent import label_type_specs, label_sizes
from brother_ql_web.configuration import Configuration
from brother_ql_web.font_helpers import get_fonts

if sys.version_info < (3, 9):
from typing import Type
BACKEND_TYPE = Type[BrotherQLBackendGeneric]
else:
BACKEND_TYPE = type[BrotherQLBackendGeneric]


def collect_fonts(configuration: Configuration) -> dict[str, dict[str, str]]:
fonts = get_fonts()
Expand All @@ -23,14 +30,14 @@ class BackendGuessingError(ValueError):
pass


def get_backend_class(configuration: Configuration) -> type[BrotherQLBackendGeneric]:
def get_backend_class(configuration: Configuration) -> BACKEND_TYPE:
try:
selected_backend = guess_backend(configuration.printer.printer)
except ValueError:
raise BackendGuessingError(
"Couln't guess the backend to use from the printer string descriptor"
)
return cast(
type[BrotherQLBackendGeneric],
BACKEND_TYPE,
backend_factory(selected_backend)["backend_class"],
)
6 changes: 3 additions & 3 deletions brother_ql_web/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import Any, cast

import bottle
from brother_ql.backends import BrotherQLBackendGeneric
from brother_ql_web.configuration import Configuration
from brother_ql_web.labels import (
LabelParameters,
Expand All @@ -14,6 +13,7 @@
generate_label,
print_label,
)
from brother_ql_web.utils import BACKEND_TYPE


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -133,7 +133,7 @@ def print_text() -> dict[str, bool | str]:
Configuration, get_config("brother_ql_web.configuration")
),
backend_class=cast(
type[BrotherQLBackendGeneric],
BACKEND_TYPE,
get_config("brother_ql_web.backend_class"),
),
)
Expand All @@ -152,7 +152,7 @@ def main(
configuration: Configuration,
fonts: dict[str, dict[str, str]],
label_sizes: list[tuple[str, str]],
backend_class: type[BrotherQLBackendGeneric],
backend_class: BACKEND_TYPE,
) -> None:
app = bottle.default_app()
app.config["brother_ql_web.configuration"] = configuration
Expand Down
2 changes: 2 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from argparse import Namespace
from io import StringIO
from contextlib import redirect_stderr
Expand Down
2 changes: 2 additions & 0 deletions tests/test_configuration.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import json
from tempfile import NamedTemporaryFile
from typing import cast
Expand Down
2 changes: 2 additions & 0 deletions tests/test_font_helpers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from unittest import TestCase

from brother_ql_web.font_helpers import get_fonts
Expand Down

0 comments on commit 715801a

Please sign in to comment.