jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/606430 )
Change subject: [IMPR] Add missing return statements ......................................................................
[IMPR] Add missing return statements
- simplify toggleTalkPage - remove return value from Page.delete method because site.deletepage does not return anything other than None - return empty list as last resort of getDeletedRevision. This may be a breaking change but improves consisteny of the result. - remove return value in protect method because site.protect does not return a value - simplify registration to return None by default - raise TypeError if Page._nskey is neither int nor str
Change-Id: I9dd2a6ea796f7528d7be81a240e298c220f9522f --- M pywikibot/page/__init__.py 1 file changed, 22 insertions(+), 20 deletions(-)
Approvals: Matěj Suchánek: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py index 9085f15..9d20f7e 100644 --- a/pywikibot/page/__init__.py +++ b/pywikibot/page/__init__.py @@ -926,18 +926,12 @@ """ ns = self.namespace() if ns < 0: # Special page - return - if self.isTalkPage(): - if self.namespace() == 1: - return Page(self.site, self.title(with_ns=False)) - else: - return Page(self.site, - '%s:%s' % (self.site.namespace(ns - 1), - self.title(with_ns=False))) - else: - return Page(self.site, - '%s:%s' % (self.site.namespace(ns + 1), - self.title(with_ns=False))) + return None + + title = self.title(with_ns=False) + new_ns = ns + (1, -1)[self.isTalkPage()] + return Page(self.site, + '{}:{}'.format(self.site.namespace(new_ns), title))
def is_categorypage(self): """Return True if the page is a Category, False otherwise.""" @@ -1957,7 +1951,9 @@ answer = 'y' self.site._noDeletePrompt = True if answer == 'y': - return self.site.deletepage(self, reason) + self.site.deletepage(self, reason) + return + else: # Otherwise mark it for deletion if mark or hasattr(self.site, '_noMarkDeletePrompt'): answer = 'y' @@ -2010,7 +2006,7 @@ @return: a list of [date, editor, comment, text, restoration marker]. text will be None, unless content is True (or has been retrieved earlier). If timestamp is not found, returns - None. + empty list. @rtype: list """ if hasattr(self, '_deletedRevs'): @@ -2018,12 +2014,14 @@ not content or 'content' in self._deletedRevs[timestamp]): return self._deletedRevs[timestamp] + for item in self.site.deletedrevs(self, start=timestamp, content=content, total=1): # should only be one item with one revision if item['title'] == self.title: if 'revisions' in item: return item['revisions'][0] + return []
def markDeletedRevision(self, timestamp, undelete=True): """ @@ -2150,7 +2148,7 @@ answer = 'y' self.site._noProtectPrompt = True if answer == 'y': - return self.site.protect(self, protections, reason, **kwargs) + self.site.protect(self, protections, reason, **kwargs)
@deprecated_args( comment='summary', oldCat='old_cat', newCat='new_cat', @@ -3306,11 +3304,11 @@
@rtype: pywikibot.Timestamp or None """ - if self.isAnonymous(): - return None - reg = self.getprops(force).get('registration') - if reg: - return pywikibot.Timestamp.fromISOformat(reg) + if not self.isAnonymous(): + reg = self.getprops(force).get('registration') + if reg: + return pywikibot.Timestamp.fromISOformat(reg) + return None
def editCount(self, force=False): """ @@ -6103,6 +6101,10 @@ ns = self.site.namespaces[default_nskey] return ns
+ raise TypeError( + 'Invalid type "{}" for Page._nskey. Must be int or str.' + .format(type(self._nskey))) + @property def site(self): """