jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/766191 )
Change subject: [IMPR] Simplify raising HiddenKeyError in LogEntry ......................................................................
[IMPR] Simplify raising HiddenKeyError in LogEntry
Change-Id: Ie81d67603ac9ac1452eeb27dd62201e47bc22505 --- M pywikibot/logentries.py 1 file changed, 13 insertions(+), 7 deletions(-)
Approvals: Matěj Suchánek: Looks good to me, but someone else must approve Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/logentries.py b/pywikibot/logentries.py index d6fe6a3..e91168b 100644 --- a/pywikibot/logentries.py +++ b/pywikibot/logentries.py @@ -54,13 +54,19 @@ """ pywikibot.debug('API log entry received:\n{!r}'.format(self), _logger) - hidden = {'action', 'logpage', 'ns', 'pageid', 'params', 'title'} - if ((key in hidden and 'actionhidden' in self) - or (key == 'comment' and 'commenthidden' in self) - or (key == 'user' and 'userhidden' in self)): - raise HiddenKeyError( - "Log entry ({}) has a hidden '{}' key and you don't have " - 'permission to view it.'.format(self['type'], key)) + hidden = { + 'actionhidden': [ + 'action', 'logpage', 'ns', 'pageid', 'params', 'title', + ], + 'commenthidden': ['comment'], + 'userhidden': ['user'], + } + for hidden_key, hidden_types in hidden.items(): + if hidden_key in self and key in hidden_types: + raise HiddenKeyError( + "Log entry ({}) has a hidden '{}' key and you don't have " + "permission to view it due to '{}'" + .format(self['type'], key, hidden_key))
raise KeyError('Log entry ({}) has no {!r} key' .format(self['type'], key))
pywikibot-commits@lists.wikimedia.org