mirror of
				https://github.com/python-escpos/python-escpos
				synced 2025-10-23 09:30:00 +00:00 
			
		
		
		
	Please mypy type checking
This commit is contained in:
		@@ -14,7 +14,7 @@ This module contains the abstract base class :py:class:`Escpos`.
 | 
				
			|||||||
import textwrap
 | 
					import textwrap
 | 
				
			||||||
from abc import ABCMeta, abstractmethod  # abstract base class support
 | 
					from abc import ABCMeta, abstractmethod  # abstract base class support
 | 
				
			||||||
from re import match as re_match
 | 
					from re import match as re_match
 | 
				
			||||||
from typing import List, Optional, Union
 | 
					from typing import List, Optional, Union, Literal
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import barcode
 | 
					import barcode
 | 
				
			||||||
import qrcode
 | 
					import qrcode
 | 
				
			||||||
@@ -114,7 +114,11 @@ class Escpos(object):
 | 
				
			|||||||
    class.
 | 
					    class.
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    _device = False  # False -> Uninitialized
 | 
					    # device status:
 | 
				
			||||||
 | 
					    #   False -> Not initialized
 | 
				
			||||||
 | 
					    #   None -> Initialized but not connected
 | 
				
			||||||
 | 
					    #   object -> The connection object (Usb(), Serial(), Network(), etc.)
 | 
				
			||||||
 | 
					    _device: Union[Literal[False], Literal[None], object] = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(self, profile=None, magic_encode_args=None, **kwargs) -> None:
 | 
					    def __init__(self, profile=None, magic_encode_args=None, **kwargs) -> None:
 | 
				
			||||||
        """Initialize ESCPOS Printer.
 | 
					        """Initialize ESCPOS Printer.
 | 
				
			||||||
@@ -129,7 +133,7 @@ class Escpos(object):
 | 
				
			|||||||
        self.close()
 | 
					        self.close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @property
 | 
					    @property
 | 
				
			||||||
    def device(self) -> object:
 | 
					    def device(self) -> Union[Literal[False], Literal[None], 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
 | 
				
			||||||
@@ -142,7 +146,7 @@ class Escpos(object):
 | 
				
			|||||||
        return self._device
 | 
					        return self._device
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @device.setter
 | 
					    @device.setter
 | 
				
			||||||
    def device(self, new_device: object):
 | 
					    def device(self, new_device: Union[Literal[False], Literal[None], object]):
 | 
				
			||||||
        self._device = new_device
 | 
					        self._device = new_device
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def open(self):
 | 
					    def open(self):
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user