diff --git a/src/escpos/escpos.py b/src/escpos/escpos.py index ac5f51e..c6ea6bf 100644 --- a/src/escpos/escpos.py +++ b/src/escpos/escpos.py @@ -129,7 +129,7 @@ class Escpos(object): self.close() @property - def device(self): + def device(self) -> object: """Implements a self-open mechanism. An attempt to get the property before open the connection diff --git a/src/escpos/printer/cups.py b/src/escpos/printer/cups.py index c7eff06..a870b9b 100644 --- a/src/escpos/printer/cups.py +++ b/src/escpos/printer/cups.py @@ -24,6 +24,7 @@ try: DEFAULT_HOST = cups.getServer() DEFAULT_PORT = cups.getPort() except ImportError: + print("Error") pass @@ -81,7 +82,7 @@ class CupsPrinter(Escpos): return is_usable() @dependency_pycups - def __init__(self, printer_name=None, *args, **kwargs): + def __init__(self, printer_name: str = "", *args, **kwargs): """Class constructor for CupsPrinter. :param printer_name: CUPS printer name (Optional) diff --git a/src/escpos/printer/file.py b/src/escpos/printer/file.py index 9eaef9a..5fa24d6 100644 --- a/src/escpos/printer/file.py +++ b/src/escpos/printer/file.py @@ -39,7 +39,9 @@ class File(Escpos): """ return is_usable() - def __init__(self, devfile="/dev/usb/lp0", auto_flush=True, *args, **kwargs): + def __init__( + self, devfile: str = "/dev/usb/lp0", auto_flush: bool = True, *args, **kwargs + ): """Initialize file printer with device file. :param devfile: Device file under dev filesystem diff --git a/src/escpos/printer/lp.py b/src/escpos/printer/lp.py index 3ccacfa..02971e9 100644 --- a/src/escpos/printer/lp.py +++ b/src/escpos/printer/lp.py @@ -61,7 +61,7 @@ class LP(Escpos): """ return is_usable() - def __init__(self, printer_name: str, *args, **kwargs): + def __init__(self, printer_name: str = "", *args, **kwargs): """LP class constructor. :param printer_name: CUPS printer name (Optional) diff --git a/src/escpos/printer/network.py b/src/escpos/printer/network.py index a33c7ff..38e6ddd 100644 --- a/src/escpos/printer/network.py +++ b/src/escpos/printer/network.py @@ -9,6 +9,7 @@ """ import socket +from typing import Union from ..escpos import Escpos @@ -50,7 +51,14 @@ class Network(Escpos): """ return is_usable() - def __init__(self, host, port=9100, timeout=60, *args, **kwargs): + def __init__( + self, + host: str = None, + port: int = 9100, + timeout: Union[int, float] = 60, + *args, + **kwargs + ): """Initialize network printer. :param host: Printer's hostname or IP address diff --git a/src/escpos/printer/serial.py b/src/escpos/printer/serial.py index 39588c9..8ebc591 100644 --- a/src/escpos/printer/serial.py +++ b/src/escpos/printer/serial.py @@ -10,6 +10,7 @@ import functools +from typing import Union from ..escpos import Escpos @@ -73,14 +74,14 @@ class Serial(Escpos): @dependency_pyserial def __init__( self, - devfile="/dev/ttyS0", - baudrate=9600, - bytesize=8, - timeout=1, - parity=None, - stopbits=None, - xonxoff=False, - dsrdtr=True, + devfile: str = "/dev/ttyS0", + baudrate: int = 9600, + bytesize: int = 8, + timeout: Union[int, float] = 1, + parity=None, # type: str? + stopbits=None, # type: int? + xonxoff: bool = False, + dsrdtr: bool = True, *args, **kwargs ): diff --git a/src/escpos/printer/usb.py b/src/escpos/printer/usb.py index 3295096..b1ee668 100644 --- a/src/escpos/printer/usb.py +++ b/src/escpos/printer/usb.py @@ -8,6 +8,7 @@ :license: MIT """ import functools +from typing import Dict, Union from ..escpos import Escpos from ..exceptions import USBNotFoundError @@ -72,12 +73,12 @@ class Usb(Escpos): def __init__( self, - idVendor, - idProduct, - usb_args=None, - timeout=0, - in_ep=0x82, - out_ep=0x01, + idVendor: str = "", + idProduct: str = "", + usb_args: Dict[str, str] = {}, + timeout: Union[int, float] = 0, + in_ep=0x82, # type: int? + out_ep=0x01, # type: int? *args, **kwargs ): diff --git a/src/escpos/printer/win32raw.py b/src/escpos/printer/win32raw.py index e7f18ab..c71fc00 100644 --- a/src/escpos/printer/win32raw.py +++ b/src/escpos/printer/win32raw.py @@ -70,7 +70,7 @@ class Win32Raw(Escpos): return is_usable() @dependency_win32print - def __init__(self, printer_name=None, *args, **kwargs): + def __init__(self, printer_name: str = "", *args, **kwargs): """Initialize default printer.""" Escpos.__init__(self, *args, **kwargs) if printer_name is not None: