Deprecate using supybot.dynamicScope without an import (#1535)

This commit is contained in:
James Lu 2023-08-12 15:36:37 -07:00
parent 5f0874b075
commit e5432ecf96

View File

@ -28,6 +28,7 @@
# POSSIBILITY OF SUCH DAMAGE. # POSSIBILITY OF SUCH DAMAGE.
### ###
import logging
import sys import sys
class DynamicScope(object): class DynamicScope(object):
@ -48,6 +49,18 @@ class DynamicScope(object):
def __setattr__(self, name, value): def __setattr__(self, name, value):
self._getLocals(name)[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: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: