Add default value to all params + type annotations

This commit is contained in:
belono 2023-09-03 20:37:41 +02:00
parent fa583e68d5
commit a7e7bc0a64
8 changed files with 33 additions and 20 deletions

View File

@ -129,7 +129,7 @@ class Escpos(object):
self.close() self.close()
@property @property
def device(self): def device(self) -> object:
"""Implements a self-open mechanism. """Implements a self-open mechanism.
An attempt to get the property before open the connection An attempt to get the property before open the connection

View File

@ -24,6 +24,7 @@ try:
DEFAULT_HOST = cups.getServer() DEFAULT_HOST = cups.getServer()
DEFAULT_PORT = cups.getPort() DEFAULT_PORT = cups.getPort()
except ImportError: except ImportError:
print("Error")
pass pass
@ -81,7 +82,7 @@ class CupsPrinter(Escpos):
return is_usable() return is_usable()
@dependency_pycups @dependency_pycups
def __init__(self, printer_name=None, *args, **kwargs): def __init__(self, printer_name: str = "", *args, **kwargs):
"""Class constructor for CupsPrinter. """Class constructor for CupsPrinter.
:param printer_name: CUPS printer name (Optional) :param printer_name: CUPS printer name (Optional)

View File

@ -39,7 +39,9 @@ class File(Escpos):
""" """
return is_usable() 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. """Initialize file printer with device file.
:param devfile: Device file under dev filesystem :param devfile: Device file under dev filesystem

View File

@ -61,7 +61,7 @@ class LP(Escpos):
""" """
return is_usable() return is_usable()
def __init__(self, printer_name: str, *args, **kwargs): def __init__(self, printer_name: str = "", *args, **kwargs):
"""LP class constructor. """LP class constructor.
:param printer_name: CUPS printer name (Optional) :param printer_name: CUPS printer name (Optional)

View File

@ -9,6 +9,7 @@
""" """
import socket import socket
from typing import Union
from ..escpos import Escpos from ..escpos import Escpos
@ -50,7 +51,14 @@ class Network(Escpos):
""" """
return is_usable() 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. """Initialize network printer.
:param host: Printer's hostname or IP address :param host: Printer's hostname or IP address

View File

@ -10,6 +10,7 @@
import functools import functools
from typing import Union
from ..escpos import Escpos from ..escpos import Escpos
@ -73,14 +74,14 @@ class Serial(Escpos):
@dependency_pyserial @dependency_pyserial
def __init__( def __init__(
self, self,
devfile="/dev/ttyS0", devfile: str = "/dev/ttyS0",
baudrate=9600, baudrate: int = 9600,
bytesize=8, bytesize: int = 8,
timeout=1, timeout: Union[int, float] = 1,
parity=None, parity=None, # type: str?
stopbits=None, stopbits=None, # type: int?
xonxoff=False, xonxoff: bool = False,
dsrdtr=True, dsrdtr: bool = True,
*args, *args,
**kwargs **kwargs
): ):

View File

@ -8,6 +8,7 @@
:license: MIT :license: MIT
""" """
import functools import functools
from typing import Dict, Union
from ..escpos import Escpos from ..escpos import Escpos
from ..exceptions import USBNotFoundError from ..exceptions import USBNotFoundError
@ -72,12 +73,12 @@ class Usb(Escpos):
def __init__( def __init__(
self, self,
idVendor, idVendor: str = "",
idProduct, idProduct: str = "",
usb_args=None, usb_args: Dict[str, str] = {},
timeout=0, timeout: Union[int, float] = 0,
in_ep=0x82, in_ep=0x82, # type: int?
out_ep=0x01, out_ep=0x01, # type: int?
*args, *args,
**kwargs **kwargs
): ):

View File

@ -70,7 +70,7 @@ class Win32Raw(Escpos):
return is_usable() return is_usable()
@dependency_win32print @dependency_win32print
def __init__(self, printer_name=None, *args, **kwargs): def __init__(self, printer_name: str = "", *args, **kwargs):
"""Initialize default printer.""" """Initialize default printer."""
Escpos.__init__(self, *args, **kwargs) Escpos.__init__(self, *args, **kwargs)
if printer_name is not None: if printer_name is not None: