From e07306d5c42b8ffef0e96efdb1734bd11d2b6ff8 Mon Sep 17 00:00:00 2001 From: InsanePrawn Date: Sun, 5 Mar 2023 18:33:13 +0100 Subject: [PATCH] wrapper: add needs_wrap(), typehint return values --- wrapper/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/wrapper/__init__.py b/wrapper/__init__.py index f7ce80a..f6f519f 100644 --- a/wrapper/__init__.py +++ b/wrapper/__init__.py @@ -14,7 +14,7 @@ wrapper_impls: dict[str, Wrapper] = { } -def get_wrapper_type(wrapper_type: Optional[str] = None): +def get_wrapper_type(wrapper_type: Optional[str] = None) -> str: return wrapper_type or config.file.wrapper.type @@ -28,14 +28,19 @@ def wrap(wrapper_type: Optional[str] = None): get_wrapper_impl(wrapper_type).wrap() -def is_wrapped(wrapper_type: Optional[str] = None): +def is_wrapped(wrapper_type: Optional[str] = None) -> bool: wrapper_type = get_wrapper_type(wrapper_type) return wrapper_type != 'none' and get_wrapper_impl(wrapper_type).is_wrapped() +def needs_wrap(wrapper_type: Optional[str] = None) -> bool: + wrapper_type = wrapper_type or get_wrapper_type() + return wrapper_type != 'none' and not is_wrapped(wrapper_type) and not config.runtime.no_wrap + + def enforce_wrap(no_wrapper=False): wrapper_type = get_wrapper_type() - if wrapper_type != 'none' and not is_wrapped(wrapper_type) and not config.runtime.no_wrap and not no_wrapper: + if needs_wrap(wrapper_type) and not no_wrapper: logging.info(f'Wrapping in {wrapper_type}') wrap()