From 5d3d2ca34b9fa0050b951b66ed4b026157dda319 Mon Sep 17 00:00:00 2001 From: Patrick Kanzler <4189642+patkan@users.noreply.github.com> Date: Sat, 28 Oct 2023 21:11:38 +0200 Subject: [PATCH 1/2] import TypedDict from typing, not from extensions (#589) TypedDict is in the supported python versions available in typing. Therefore an import from potentially uninstalled typing_extensions is not necessary. fixes #560 --- src/escpos/types/__init__.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/escpos/types/__init__.py b/src/escpos/types/__init__.py index 25ba4de..64c138c 100644 --- a/src/escpos/types/__init__.py +++ b/src/escpos/types/__init__.py @@ -1,9 +1,7 @@ # -*- coding: utf-8 -*- """Custom types.""" -from typing import Dict - -from typing_extensions import TypedDict +from typing import Dict, TypedDict class ConstTxtStyleClass(TypedDict): From 3b6551004ffa6c1fd8a9c19df642244f4af708a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benito=20L=C3=B3pez?= Date: Tue, 31 Oct 2023 13:55:48 +0100 Subject: [PATCH 2/2] Restore types-pywin32 (#591) * Restore types-pywin32 dependency * Restore pywin32 type annotations in win32raw * Add return type to _raw() --- src/escpos/printer/win32raw.py | 18 ++++++++++-------- tox.ini | 1 + 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/escpos/printer/win32raw.py b/src/escpos/printer/win32raw.py index bb04a42..2b26732 100644 --- a/src/escpos/printer/win32raw.py +++ b/src/escpos/printer/win32raw.py @@ -10,7 +10,7 @@ import functools import logging -from typing import Literal, Optional, Type, Union +from typing import Any, Literal, Optional, Union from ..escpos import Escpos from ..exceptions import DeviceNotFoundError @@ -20,9 +20,11 @@ _DEP_WIN32PRINT = False try: + import pywintypes import win32print _DEP_WIN32PRINT = True + PyPrinterHANDLE: Any = win32print.OpenPrinter except ImportError: pass @@ -83,7 +85,7 @@ class Win32Raw(Escpos): self._device: Union[ Literal[False], Literal[None], - Type[win32print.OpenPrinter], + "PyPrinterHANDLE", ] = False @property @@ -115,15 +117,15 @@ class Win32Raw(Escpos): self.printer_name = self.printer_name or win32print.GetDefaultPrinter() assert self.printer_name in self.printers, "Incorrect printer name" # Open device - self.device: Optional[ - Type[win32print.OpenPrinter] - ] = win32print.OpenPrinter(self.printer_name) + self.device: Optional["PyPrinterHANDLE"] = win32print.OpenPrinter( + self.printer_name + ) if self.device: self.current_job = win32print.StartDocPrinter( - self.device, 1, (job_name, None, "RAW") + self.device, 1, (job_name, "", "RAW") ) win32print.StartPagePrinter(self.device) - except AssertionError as e: + except (AssertionError, pywintypes.error) as e: # Raise exception or log error and cancel self.device = None if raise_not_found: @@ -146,7 +148,7 @@ class Win32Raw(Escpos): win32print.ClosePrinter(self._device) self._device = False - def _raw(self, msg): + def _raw(self, msg) -> None: """Print any command sent in raw format. :param msg: arbitrary code to be printed diff --git a/tox.ini b/tox.ini index 2abdad6..bafb326 100644 --- a/tox.ini +++ b/tox.ini @@ -57,6 +57,7 @@ deps = mypy types-appdirs types-Pillow types-pyserial + types-pywin32>=306.0.0.6 hypothesis>=6.83 jaconv commands = mypy src test