comparison libervia/backend/core/constants.py @ 4229:dd9bc7d791d7

core (constants): use `bool_type`: Using `bool` for type hint in `Const.bool_const` if conflicting with `Const.bool` method. To avoid this, `bool_type` is used as an alias to `bool`.
author Goffi <goffi@goffi.org>
date Sat, 06 Apr 2024 12:14:10 +0200
parents 5a0bddfa34ac
children 898db6daf0d0
comparison
equal deleted inserted replaced
4228:79a4870cfbdf 4229:dd9bc7d791d7
31 from getpass import getuser 31 from getpass import getuser
32 except ImportError: 32 except ImportError:
33 logged_user = "unkonwn" 33 logged_user = "unkonwn"
34 else: 34 else:
35 logged_user = getuser() 35 logged_user = getuser()
36
37
38 bool_type = bool
36 39
37 40
38 class Const(object): 41 class Const(object):
39 42
40 ## Application ## 43 ## Application ##
453 cls.LOG_OPT_LOGGER, 456 cls.LOG_OPT_LOGGER,
454 cls.LOG_OPT_OUTPUT, 457 cls.LOG_OPT_OUTPUT,
455 ) 458 )
456 459
457 @classmethod 460 @classmethod
458 def bool(cls, value: str) -> bool: 461 def bool(cls, value: str) -> bool_type:
459 """@return (bool): bool value for associated constant""" 462 """@return (bool): bool value for associated constant"""
460 assert isinstance(value, str) 463 assert isinstance(value, str)
461 return value.lower() in (cls.BOOL_TRUE, "1", "yes", "on", "y", "t") 464 return value.lower() in (cls.BOOL_TRUE, "1", "yes", "on", "y", "t")
462 465
463 @classmethod 466 @classmethod
464 def bool_const(cls, value: bool) -> str: 467 def bool_const(cls, value: bool_type) -> str:
465 """@return (str): constant associated to bool value""" 468 """@return (str): constant associated to bool value"""
466 assert isinstance(value, bool) 469 assert isinstance(value, bool)
467 return cls.BOOL_TRUE if value else cls.BOOL_FALSE 470 return cls.BOOL_TRUE if value else cls.BOOL_FALSE
468 471
469 472