jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/633138 )
Change subject: [doc] More documentation for OptionHandler/bot options usage
......................................................................
[doc] More documentation for OptionHandler/bot options usage
Change-Id: Id5e184a12bbbf95620909f63381cc4e1a60c7a9a
---
M pywikibot/bot.py
1 file changed, 40 insertions(+), 1 deletion(-)
Approvals:
Mpaa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 82cf842..40a949e 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -1042,7 +1042,44 @@
class OptionHandler:
- """Class to get and set options."""
+ """Class to get and set options.
+
+ How to use options of OptionHandler and its BaseBot subclasses:
+ First define a available_options class attribute to define all
+ available options:
+
+ available_options = {'foo': 'bar', 'bar': 42, 'baz': False}
+
+ Or you may update the predefined setting in the class initializer.
+ BaseBot predefines a 'always' options and sets it to False:
+
+ self.available_options.update(always=True, another_option='Yes')
+
+ Now you can instantiate an OptionHandler or BaseBot class passing
+ options other than default values:
+
+ >>> bot = OptionHandler(baz=True)
+
+ You can access bot options either as keyword item or attribute:
+
+ >>> bot.opt.foo
+ 'bar'
+ >>> bot.opt['bar']
+ 42
+ >>> bot.opt.baz # default was overridden
+ True
+
+ You can set the options in the same way:
+
+ >>> bot.opt.bar = 4711
+ >>> bot.opt['baz'] = None
+ >>>
+
+ Or you can use the option as a dict:
+
+ >>> 'Option opt.{foo} is {bar}'.format_map(bot.opt)
+ 'Option opt.bar is 4711'
+ """
# Handler configuration.
# Only the keys of the dict can be passed as init options
@@ -1139,6 +1176,8 @@
If the subclass does not set a generator, or does not override
treat() or run(), NotImplementedError is raised.
+
+ For bot options handling refer OptionHandler class above.
"""
# Handler configuration.
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/633138
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Id5e184a12bbbf95620909f63381cc4e1a60c7a9a
Gerrit-Change-Number: 633138
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Mpaa <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits