jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[cleanup] Remove deprecated OptionHandler.options dict

Also show a FutureWarning for deprecated availableOptions property,
and setOptions/getOption methods

Change-Id: Ic11750d019ff713f8b4143bb87c2bd8f01501d27
---
M pywikibot/bot.py
M tests/bot_tests.py
2 files changed, 6 insertions(+), 54 deletions(-)

diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 0d90522..711525a 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -1018,7 +1018,6 @@

def __init__(self, classname, options):
self._classname = classname
- self._options = {}
super().__init__(options)

def __missing__(self, key):
@@ -1031,26 +1030,11 @@

def __setattr__(self, name, value):
"""Set item or attribute."""
- if name not in ('_classname', '_options'):
+ if name != '_classname':
self.__setitem__(name, value)
else:
super().__setattr__(name, value)

- def __getitem__(self, key):
- """Update options fro backward compatibility and get item."""
- self.update_options()
- return super().__getitem__(key)
-
- def __setitem__(self, key, value):
- """Set item in dict and deprecated option dict."""
- if key in self._options:
- self._options[key] = value
- super().__setitem__(key, value)
-
- def update_options(self):
- """Update dict from deprecated options for backward compatibility."""
- self.update(self._options)
-

_DEPRECATION_MSG = 'Optionhandler.opt.option attribute ' \
'or Optionhandler.opt[option] item'
@@ -1114,12 +1098,12 @@
self.set_options(**kwargs)

@property
- @deprecated('available_options', since='20201006')
+ @deprecated('available_options', since='20201006', future_warning=True)
def availableOptions(self):
"""DEPRECATED. Available_options class property."""
return self.available_options

- @deprecated('set_options', since='20201006')
+ @deprecated('set_options', since='20201006', future_warning=True)
def setOptions(self, **kwargs): # pragma: no cover
"""DEPRECATED. Set the instance options."""
self.set_options(**kwargs)
@@ -1149,7 +1133,7 @@
pywikibot.warning('{} is not a valid option. It was ignored.'
.format(opt))

- @deprecated(_DEPRECATION_MSG, since='20201006')
+ @deprecated(_DEPRECATION_MSG, since='20201006', future_warning=True)
def getOption(self, option): # pragma: no cover
"""DEPRECATED. Get the current value of an option.

@@ -1159,25 +1143,6 @@
"""
return self.opt[option]

- @property
- @deprecated(_DEPRECATION_MSG, since='20201006', future_warning=True)
- def options(self): # pragma: no cover
- """DEPRECATED. Return changed options."""
- return self.opt._options
-
- @options.setter
- @deprecated(_DEPRECATION_MSG, since='20201006', future_warning=True)
- def options(self, options): # pragma: no cover
- """DEPRECATED. Return changed options."""
- self.set_options(**options)
-
- def __getattribute__(self, name):
- """Update options for backward compatibility of options property."""
- attr = super().__getattribute__(name)
- if name == 'opt':
- attr.update_options()
- return attr
-

class BaseBot(OptionHandler):

diff --git a/tests/bot_tests.py b/tests/bot_tests.py
index 04a414a..53d9b96 100644
--- a/tests/bot_tests.py
+++ b/tests/bot_tests.py
@@ -1,6 +1,6 @@
"""Bot tests."""
#
-# (C) Pywikibot team, 2015-2020
+# (C) Pywikibot team, 2015-2021
#
# Distributed under the terms of the MIT license.
#
@@ -11,6 +11,7 @@
import pywikibot.bot
from pywikibot import i18n
from pywikibot.tools import suppress_warnings
+
from tests.aspects import (
DefaultSiteTestCase,
SiteAttributeTestCase,
@@ -392,20 +393,6 @@
self.assertEqual(oh.opt.baz, 'Hey')
self.assertEqual(oh.opt['baz'], 'Hey')
self.assertNotIn('baz', oh.opt.__dict__)
- with suppress_warnings(r'pywikibot\.bot\.OptionHandler\.options'):
- self.assertEqual(oh.options['baz'], 'Hey')
-
- def test_options(self):
- """Test deprecated option attribute."""
- oh = self.option_handler
- with suppress_warnings(r'pywikibot\.bot\.OptionHandler\.options'):
- self.assertNotIn('bar', oh.options)
- self.assertIn('baz', oh.options)
- self.assertTrue(oh.options['baz'])
- self.assertEqual(oh.opt['baz'], oh.options['baz'])
- oh.options['baz'] = False
- self.assertFalse(oh.options['baz'])
- self.assertFalse(oh.opt.baz)


if __name__ == '__main__': # pragma: no cover

To view, visit change 689885. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ic11750d019ff713f8b4143bb87c2bd8f01501d27
Gerrit-Change-Number: 689885
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged