From c29a03aeda082ab53945e4b5d9fbf90b3ed26fca Mon Sep 17 00:00:00 2001 From: alemidev Date: Thu, 28 Apr 2022 13:44:17 +0200 Subject: [PATCH] jank fix for 'Treepuncher' type hint --- src/treepuncher/addon.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/treepuncher/addon.py b/src/treepuncher/addon.py index e821b0c..9b54cf9 100644 --- a/src/treepuncher/addon.py +++ b/src/treepuncher/addon.py @@ -58,7 +58,11 @@ class Addon: self.name = type(self).__name__ cfg = self._client.config opts: Dict[str, Any] = {} - cfg_clazz = get_type_hints(type(self), globalns=globals())['config'] + localns = { 'Treepuncher': None } # TODO jank fix! + # get_type_hints attempts to instantiate all string hints (such as 'Treepuncher'). + # But we can't import Treepuncher here: would be a cyclic import! + # We don't care about Treepuncher annotation, so we force it to be None + cfg_clazz = get_type_hints(type(self), globalns=globals(), localns=localns)['config'] if cfg_clazz is not ConfigObject: for field in fields(cfg_clazz): default = field.default if field.default is not MISSING \