jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] config2: Automatically list imports ......................................................................
[IMPROV] config2: Automatically list imports
Instead of having to remember adding the imports manually in a tuple this automatically iterates over the global variables and generates the list (technically a frozenset) from there.
Change-Id: Iaeea9e6e5579153d0211b7625eec607ba65b8748 --- M pywikibot/config2.py 1 file changed, 7 insertions(+), 6 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/config2.py b/pywikibot/config2.py index 5169b0c..6e7954d 100644 --- a/pywikibot/config2.py +++ b/pywikibot/config2.py @@ -29,16 +29,17 @@
from warnings import warn
+# This frozen set should contain all imported modules/variables, so it must +# occur directly after the imports. At that point globals() only contains the +# names and some magic variables (like __name__) +_imports = frozenset(name for name in globals() if not name.startswith('_')) +
class _ConfigurationDeprecationWarning(UserWarning):
"""Feature that is no longer supported."""
pass - - -# Please keep _imported_modules in sync with the imports above -_imported_modules = ('collections', 'os', 'stat', 'sys')
# IMPORTANT: # Do not change any of the variables in this file. Instead, make @@ -816,7 +817,7 @@ # System-level and User-level changes. # Store current variables and their types. _glv = dict((_key, _val) for _key, _val in globals().items() - if _key[0] != '_' and _key not in _imported_modules) + if _key[0] != '_' and _key not in _imports) _gl = list(_glv.keys()) _tp = {} for _key in _gl: @@ -865,7 +866,7 @@ for _key, _val in list(_uc.items()): if _key.startswith('_'): pass - elif _key in _imported_modules: + elif _key in _imports: pass elif _key in _gl: nt = type(_val)
pywikibot-commits@lists.wikimedia.org