From ed8ec0788ae98f27cdc44beb18e33ae72a3bb3a5 Mon Sep 17 00:00:00 2001 From: Patrick Kanzler Date: Sun, 8 Nov 2020 23:45:25 +0100 Subject: [PATCH] start with type annotation --- src/escpos/capabilities.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/escpos/capabilities.py b/src/escpos/capabilities.py index 80f88a1..5ef1f1e 100644 --- a/src/escpos/capabilities.py +++ b/src/escpos/capabilities.py @@ -11,6 +11,8 @@ import yaml from tempfile import gettempdir import platform +from typing import Any, Dict + logging.basicConfig() logger = logging.getLogger(__name__) @@ -45,7 +47,7 @@ if full_load: logger.debug('Finished loading capabilities took %.2fs', time.time() - t0) -PROFILES = CAPABILITIES['profiles'] +PROFILES: Dict[str, Any] = CAPABILITIES['profiles'] class NotSupported(Exception): @@ -65,12 +67,12 @@ class BaseProfile(object): features, colors and more. """ - profile_data = {} + profile_data: Dict[str, Any] = {} def __getattr__(self, name): return self.profile_data[name] - def get_font(self, font): + def get_font(self, font) -> int: """Return the escpos index for `font`. Makes sure that the requested `font` is valid. """ @@ -97,7 +99,7 @@ class BaseProfile(object): return {v: k for k, v in self.codePages.items()} -def get_profile(name=None, **kwargs): +def get_profile(name:str=None, **kwargs): """Get the profile by name; if no name is given, return the default profile. """ @@ -111,7 +113,7 @@ def get_profile(name=None, **kwargs): CLASS_CACHE = {} -def get_profile_class(name): +def get_profile_class(name: str): """For the given profile name, load the data from the external database, then generate dynamically a class. """