more limited jank fix

This commit is contained in:
əlemi 2022-04-29 00:45:46 +02:00
parent c2a9726ec6
commit 98d3967dfe
No known key found for this signature in database
GPG key ID: BBCBFE5D7244634E
2 changed files with 2 additions and 3 deletions

View file

@ -42,7 +42,7 @@ def main():
for addon in addons: for addon in addons:
help_text += f"\n {addon.__name__} \t{addon.__doc__ or ''}" help_text += f"\n {addon.__name__} \t{addon.__doc__ or ''}"
cfg_clazz = get_type_hints(addon, globalns=globals())['config'] cfg_clazz = get_type_hints(addon, localns={'Treepuncher':Treepuncher})['config']
if cfg_clazz is ConfigObject: if cfg_clazz is ConfigObject:
continue # it's the superclass type hint continue # it's the superclass type hint
for field in fields(cfg_clazz): for field in fields(cfg_clazz):

View file

@ -58,11 +58,10 @@ class Addon:
self.name = type(self).__name__ self.name = type(self).__name__
cfg = self._client.config cfg = self._client.config
opts: Dict[str, Any] = {} opts: Dict[str, Any] = {}
localns = { 'Treepuncher': None } # TODO jank fix!
# get_type_hints attempts to instantiate all string hints (such as 'Treepuncher'). # get_type_hints attempts to instantiate all string hints (such as 'Treepuncher').
# But we can't import Treepuncher here: would be a cyclic import! # 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 # 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'] cfg_clazz = get_type_hints(type(self), localns={'Treepuncher': None})['config'] # TODO jank localns override
if cfg_clazz is not ConfigObject: if cfg_clazz is not ConfigObject:
for field in fields(cfg_clazz): for field in fields(cfg_clazz):
default = field.default if field.default is not MISSING \ default = field.default if field.default is not MISSING \