jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/841532 )
Change subject: [cleanup] deprecate Page.editTime() method ......................................................................
[cleanup] deprecate Page.editTime() method
Page.editTime can be easily replaced by Page.latest_revision.timestamp. We also have no method for the creation time but Page.oldest_revision.timestamp is often used for this purpose.
Change-Id: I4485655fcb05b339a67ced4c7e4e1dcc828023c0 --- M pywikibot/page/_page.py M scripts/category_redirect.py M scripts/clean_sandbox.py M scripts/newitem.py M scripts/patrol.py M tests/edit_tests.py M tests/page_tests.py 7 files changed, 42 insertions(+), 16 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page/_page.py b/pywikibot/page/_page.py index 53f86c9..ded889b 100644 --- a/pywikibot/page/_page.py +++ b/pywikibot/page/_page.py @@ -54,6 +54,7 @@ from pywikibot.tools import ( ComparableMixin, cached, + deprecated, first_upper, issue_deprecation_warning, remove_last_args, @@ -510,8 +511,20 @@ self._revid = value
@property - def latest_revision(self): - """Return the current revision for this page.""" + def latest_revision(self) -> 'pywikibot.page.Revision': + """Return the current revision for this page. + + **Example:** + + >>> site = pywikibot.Site() + >>> page = pywikibot.Page(site, 'Main Page') + ... # get the latest timestamp of that page + >>> edit_time = page.latest_revision.timestamp + >>> type(edit_time) + <class 'pywikibot.time.Timestamp'> + + .. seealso:: :attr:`oldest_revision` + """ rev = self._latest_cached_revision() if rev is not None: return rev @@ -725,8 +738,14 @@
return None
+ @deprecated('latest_revision.timestamp', since='8.0.0') def editTime(self) -> pywikibot.Timestamp: - """Return timestamp of last revision to page.""" + """Return timestamp of last revision to page. + + .. deprecated:: 8.0.0 + Use :attr:`latest_revision.timestamp<latest_revision>` + instead. + """ return self.latest_revision.timestamp
def exists(self) -> bool: @@ -740,11 +759,19 @@ raise InvalidPageError(self)
@property - def oldest_revision(self): - """ - Return the first revision of this page. + def oldest_revision(self) -> 'pywikibot.page.Revision': + """Return the first revision of this page.
- :rtype: :py:obj:`Revision` + **Example:** + + >>> site = pywikibot.Site() + >>> page = pywikibot.Page(site, 'Main Page') + ... # get the creation timestamp of that page + >>> creation_time = page.oldest_revision.timestamp + >>> type(creation_time) + <class 'pywikibot.time.Timestamp'> + + .. seealso:: :attr:`latest_revision` """ return next(self.revisions(reverse=True, total=1))
diff --git a/scripts/category_redirect.py b/scripts/category_redirect.py index 53db97c..9f44311 100755 --- a/scripts/category_redirect.py +++ b/scripts/category_redirect.py @@ -174,9 +174,7 @@ """Return True if cat not edited during cooldown period, else False.""" today = pywikibot.Timestamp.now() deadline = today + timedelta(days=-self.opt.delay) - if cat.editTime() is None: - raise RuntimeError - return deadline > cat.editTime() + return deadline > cat.latest_revision.timestamp
def get_log_text(self): """Rotate log text and return the most recent text.""" diff --git a/scripts/clean_sandbox.py b/scripts/clean_sandbox.py index 261bebf..5c63464 100755 --- a/scripts/clean_sandbox.py +++ b/scripts/clean_sandbox.py @@ -224,7 +224,7 @@ 'Standard content was changed, sandbox cleaned.') else: edit_delta = (datetime.datetime.utcnow() - - sandbox_page.editTime()) + - sandbox_page.latest_revision.timestamp) delta = self.delay_td - edit_delta # Is the last edit more than 'delay' minutes ago? if delta <= datetime.timedelta(0): diff --git a/scripts/newitem.py b/scripts/newitem.py index b9ebe24..510fe29 100755 --- a/scripts/newitem.py +++ b/scripts/newitem.py @@ -141,7 +141,7 @@ if super().skip_page(page): return True
- if page.editTime() > self.lastEditBefore: + if page.latest_revision.timestamp > self.lastEditBefore: pywikibot.info( f'Last edit on {page} was on {page.latest_revision.timestamp}.' f'\nToo recent. Skipping.') diff --git a/scripts/patrol.py b/scripts/patrol.py index 8f01d16..e29c8b2 100755 --- a/scripts/patrol.py +++ b/scripts/patrol.py @@ -157,7 +157,7 @@ # Parse whitelist self.whitelist = self.parse_page_tuples(wikitext, self.user) # Record timestamp - self.whitelist_ts = whitelist_page.editTime() + self.whitelist_ts = whitelist_page.latest_revision.timestamp self.whitelist_load_ts = time.time() except Exception as e: # cascade if there isn't a whitelist to fallback on diff --git a/tests/edit_tests.py b/tests/edit_tests.py index 6fb8834..1b0413f 100755 --- a/tests/edit_tests.py +++ b/tests/edit_tests.py @@ -97,11 +97,11 @@
source.text = 'Lorem ipsum dolor sit amet' source.save() - first_rev = source.editTime() + first_rev = source.latest_revision.timestamp
source.text = 'Lorem ipsum dolor sit amet is a common test phrase' source.save() - second_rev = source.editTime() + second_rev = source.latest_revision.timestamp
dest.text = 'Merge history page unit test destination' dest.save() diff --git a/tests/page_tests.py b/tests/page_tests.py index 47a0d07..6b29f43 100755 --- a/tests/page_tests.py +++ b/tests/page_tests.py @@ -462,7 +462,8 @@ self.assertIsInstance(mainpage.isDisambig(), bool) self.assertIsInstance(mainpage.has_permission(), bool) self.assertIsInstance(mainpage.botMayEdit(), bool) - self.assertIsInstance(mainpage.editTime(), pywikibot.Timestamp) + self.assertIsInstance(mainpage.latest_revision.timestamp, + pywikibot.Timestamp) self.assertIsInstance(mainpage.permalink(), str)
def test_talk_page(self):
pywikibot-commits@lists.wikimedia.org