From e07553c3627b80f20cdc81a35030bf0540924db8 Mon Sep 17 00:00:00 2001 From: jesopo Date: Tue, 30 Oct 2018 14:58:48 +0000 Subject: Add type/return hints throughout src/ and, in doing so, fix some cyclical references. --- src/Exports.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'src/Exports.py') diff --git a/src/Exports.py b/src/Exports.py index 8baca50d..68b25933 100644 --- a/src/Exports.py +++ b/src/Exports.py @@ -1,28 +1,18 @@ - - -class ExportsContext(object): - def __init__(self, parent, context): - self._parent = parent - self.context = context - - def add(self, setting, value): - self._parent._context_add(self.context, setting, value) - def get_all(self, setting): - return self._parent.get_all(setting) +import typing class Exports(object): def __init__(self): self._exports = {} self._context_exports = {} - def new_context(self, context): + def new_context(self, context: str) -> "ExportsContext": return ExportsContext(self, context) - def add(self, setting, value): + def add(self, setting: str, value: typing.Any): self._add(None, setting, value) - def _context_add(self, context, setting, value): + def _context_add(self, context: str, setting: str, value: typing.Any): self._add(context, setting, value) - def _add(self, context, setting, value): + def _add(self, context: str, setting: str, value: typing.Any): if context == None: if not setting in self_exports: self._exports[setting] = [] @@ -34,11 +24,21 @@ class Exports(object): self._context_exports[context][setting] = [] self._context_exports[context][setting].append(value) - def get_all(self, setting): + def get_all(self, setting: str) -> typing.List[typing.Any]: return self._exports.get(setting, []) + sum([ exports.get(setting, []) for exports in self._context_exports.values()], []) - def purge_context(self, context): + def purge_context(self, context: str): if context in self._context_exports: del self._context_exports[context] + +class ExportsContext(object): + def __init__(self, parent: Exports, context: str): + self._parent = parent + self.context = context + + def add(self, setting: str, value: typing.Any): + self._parent._context_add(self.context, setting, value) + def get_all(self, setting: str) -> typing.List[typing.Any]: + return self._parent.get_all(setting) -- cgit v1.3.1-10-gc9f91