From 8f54dfed003fab1ce09f33c8da6a655ca3246f19 Mon Sep 17 00:00:00 2001 From: belono Date: Sat, 14 Oct 2023 00:44:50 +0200 Subject: [PATCH] Deprecate pywin32-stubs, too --- setup.cfg | 2 -- src/escpos/printer/win32raw.py | 12 ++++++------ tox.ini | 1 - 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/setup.cfg b/setup.cfg index 80ede44..44836c4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -68,13 +68,11 @@ cups = pycups; platform_system!='Windows' win32 = pywin32; platform_system=='Windows' - pywin32-stubs; platform_system=='Windows' all = pyusb>=1.0.0 pyserial pycups; platform_system!='Windows' pywin32; platform_system=='Windows' - pywin32-stubs; platform_system=='Windows' [flake8] exclude = .git,.tox,.github,.eggs,__pycache__,doc/conf.py,build,dist,capabilities-data,test,src/escpos/constants.py diff --git a/src/escpos/printer/win32raw.py b/src/escpos/printer/win32raw.py index 5a59f47..125551d 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, Union +from typing import Literal, Optional, Type, Union from ..escpos import Escpos from ..exceptions import DeviceNotFoundError @@ -20,8 +20,6 @@ _DEP_WIN32PRINT = False try: - import pywintypes - import win32helper.win32typing as _win32typing # pywin32-stubs package import win32print _DEP_WIN32PRINT = True @@ -83,7 +81,9 @@ class Win32Raw(Escpos): self.job_name = "" self._device: Union[ - Literal[False], Literal[None], "_win32typing.PyPrinterHANDLE" + Literal[False], + Literal[None], + Type[win32print.OpenPrinter], ] = False @property @@ -118,14 +118,14 @@ class Win32Raw(Escpos): assert self.printer_name in self.printers, "Incorrect printer name" # Open device self.device: Optional[ - "_win32typing.PyPrinterHANDLE" + Type[win32print.OpenPrinter] ] = win32print.OpenPrinter(self.printer_name) if self.device: self.current_job = win32print.StartDocPrinter( self.device, 1, (job_name, None, "RAW") ) win32print.StartPagePrinter(self.device) - except (AssertionError, pywintypes.error) as e: + except AssertionError as e: # Raise exception or log error and cancel self.device = None if raise_not_found: diff --git a/tox.ini b/tox.ini index 71f2cf8..2abdad6 100644 --- a/tox.ini +++ b/tox.ini @@ -57,7 +57,6 @@ deps = mypy types-appdirs types-Pillow types-pyserial - ; types-pywin32 hypothesis>=6.83 jaconv commands = mypy src test