From e5432ecf966bc7064e7fa1bf8e62076426a4fa19 Mon Sep 17 00:00:00 2001 From: James Lu Date: Sat, 12 Aug 2023 15:36:37 -0700 Subject: [PATCH] Deprecate using supybot.dynamicScope without an import (#1535) --- src/dynamicScope.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/dynamicScope.py b/src/dynamicScope.py index 40682a6e2..b7dddf429 100644 --- a/src/dynamicScope.py +++ b/src/dynamicScope.py @@ -28,6 +28,7 @@ # POSSIBILITY OF SUCH DAMAGE. ### +import logging import sys class DynamicScope(object): @@ -48,6 +49,18 @@ class DynamicScope(object): def __setattr__(self, name, value): self._getLocals(name)[name] = value -(__builtins__ if isinstance(__builtins__, dict) else __builtins__.__dict__)['dynamic'] = DynamicScope() +class _DynamicScopeBuiltinsWrapper(DynamicScope): + def __getattr__(self, name): + _logger = logging.getLogger('supybot') + _logger.warning('Using DynamicScope without an explicit import is ' + 'deprecated and will be removed in a future Limnoria ' + 'version. Use instead: ' + 'from supybot.dynamicScope import dynamic', + stacklevel=2, stack_info=True) + return super().__getattr__(name) + +dynamic = DynamicScope() +(__builtins__ if isinstance(__builtins__, dict) else __builtins__.__dict__)['dynamic'] = \ + _DynamicScopeBuiltinsWrapper() # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: