jenkins-bot submitted this change.

View Change

Approvals: D3r1ck01: Looks good to me, approved jenkins-bot: Verified
[cleanup] Drop timestamp as since parameter in deprecation warnings

- deprecation warnings only accepts release numbers
- change all remaining timestamps to version numbers

Change-Id: I85644fae7864d284b6f908d891d6fc83694302e4
---
M pywikibot/config.py
M pywikibot/exceptions.py
M pywikibot/page/__init__.py
M pywikibot/page/_revision.py
M pywikibot/pagegenerators.py
M pywikibot/site/_apisite.py
M pywikibot/tools/_deprecate.py
M scripts/solve_disambiguation.py
8 files changed, 64 insertions(+), 78 deletions(-)

diff --git a/pywikibot/config.py b/pywikibot/config.py
index 09c185f..6600e28 100644
--- a/pywikibot/config.py
+++ b/pywikibot/config.py
@@ -385,7 +385,7 @@
family_files = {}


-@deprecated('family_files[family_name] = file_path', since='20210305')
+@deprecated('family_files[family_name] = file_path', since='6.0.0')
def register_family_file(family_name: str, file_path: str) -> None:
"""Register a single family class file.

diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py
index 211c6c1..de97765 100644
--- a/pywikibot/exceptions.py
+++ b/pywikibot/exceptions.py
@@ -162,7 +162,7 @@
removed.
"""
#
-# (C) Pywikibot team, 2008-2021
+# (C) Pywikibot team, 2008-2022
#
# Distributed under the terms of the MIT license.
#
@@ -303,7 +303,7 @@
elif re.search(r'%\(\w+\)s', self.message):
issue_deprecation_warning("'%' style messages are deprecated, "
'please use str.format() style instead',
- since='20210504')
+ since='6.2.0')
msg = self.message % self.__dict__
elif '%s' in self.message:
msg = self.message % page
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index afe7df4..91a74d2 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -1035,7 +1035,7 @@
"""
return self.site.page_can_be_edited(self, action)

- @deprecated("Page.has_permission('edit')", since='20200208')
+ @deprecated("Page.has_permission('edit')", since='3.0.20200508')
def canBeEdited(self): # pragma: no cover
"""DEPRECATED. Determine whether the page may be edited."""
return self.has_permission()
@@ -2391,7 +2391,7 @@
url_param=url_param)
return self.latest_file_info.thumburl

- @deprecated('file_is_shared', since='20200618')
+ @deprecated('file_is_shared', since='3.0.20200703')
def fileIsShared(self) -> bool: # pragma: no cover
"""DEPRECATED. Check if the image is stored on Wikimedia Commons."""
return self.file_is_shared()
diff --git a/pywikibot/page/_revision.py b/pywikibot/page/_revision.py
index ab0056a..fcdc140 100644
--- a/pywikibot/page/_revision.py
+++ b/pywikibot/page/_revision.py
@@ -1,6 +1,6 @@
"""Object representing page revision."""
#
-# (C) Pywikibot team, 2008-2021
+# (C) Pywikibot team, 2008-2022
#
# Distributed under the terms of the MIT license.
#
@@ -103,7 +103,7 @@
.format(self.__class__.__name__, key))

@property
- @deprecated('parentid property', since='20200802')
+ @deprecated('parentid property', since='4.0.0')
def parent_id(self) -> int:
"""DEPRECATED. Return id of parent/previous revision.

@@ -115,7 +115,7 @@
return self.parentid

@property
- @deprecated('contentmodel', since='20200802')
+ @deprecated('contentmodel', since='4.0.0')
def content_model(self) -> str:
"""DEPRECATED. Return content model of the revision.

diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index 53e6c6d..0190518 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -1446,7 +1446,7 @@
return gen


-@deprecated('File.usingPages()', since='20200515')
+@deprecated('File.usingPages()', since='3.0.20200609')
def FileLinksGenerator(referredFilePage: 'pywikibot.page.FilePage',
total: Optional[int] = None,
content: bool = False
@@ -1456,7 +1456,7 @@
content=content) # pragma: no cover


-@deprecated('Page.imagelinks()', since='20200515')
+@deprecated('Page.imagelinks()', since='3.0.20200609')
def ImagesPageGenerator(pageWithImages: 'pywikibot.page.Page',
total: Optional[int] = None,
content: bool = False
@@ -1535,7 +1535,7 @@
yield s


-@deprecated('Page.linkedPages()', since='20200515')
+@deprecated('Page.linkedPages()', since='3.0.20200609')
def LinkedPageGenerator(linkingPage: 'pywikibot.page.Page',
total: Optional[int] = None,
content: bool = False
@@ -1630,7 +1630,7 @@
yield pywikibot.Page(pywikibot.Link(title, site))


-@deprecated('site.load_pages_from_pageids()', since='20200515')
+@deprecated('site.load_pages_from_pageids()', since='3.0.20200609')
def PagesFromPageidGenerator(pageids: Iterable[str],
site: OPT_SITE_TYPE = None
) -> Iterable['pywikibot.page.Page']:
@@ -2319,7 +2319,7 @@
yield page


-@deprecated('Site.unusedfiles()', since='20200515')
+@deprecated('Site.unusedfiles()', since='3.0.20200609')
def UnusedFilesGenerator(total: Optional[int] = None, # pragma: no cover
site: OPT_SITE_TYPE = None
) -> Iterable['pywikibot.page.FilePage']:
@@ -2334,7 +2334,7 @@
return site.unusedfiles(total=total)


-@deprecated('Site.withoutinterwiki()', since='20200515')
+@deprecated('Site.withoutinterwiki()', since='3.0.20200609')
def WithoutInterwikiPageGenerator(total: Optional[int] = None,
site: OPT_SITE_TYPE = None
) -> Iterable['pywikibot.page.Page']:
@@ -2349,7 +2349,7 @@
return site.withoutinterwiki(total=total)


-@deprecated('Site.uncategorizedcategories()', since='20200515')
+@deprecated('Site.uncategorizedcategories()', since='3.0.20200609')
def UnCategorizedCategoryGenerator(total: Optional[int] = 100,
site: OPT_SITE_TYPE = None
) -> Iterable['pywikibot.Category']:
@@ -2364,7 +2364,7 @@
return site.uncategorizedcategories(total=total)


-@deprecated('Site.uncategorizedimages()', since='20200515')
+@deprecated('Site.uncategorizedimages()', since='3.0.20200609')
def UnCategorizedImageGenerator(total: int = 100, # pragma: no cover
site: OPT_SITE_TYPE = None
) -> Iterable['pywikibot.page.FilePage']:
@@ -2379,7 +2379,7 @@
return site.uncategorizedimages(total=total)


-@deprecated('Site.uncategorizedpages()', since='20200515')
+@deprecated('Site.uncategorizedpages()', since='3.0.20200609')
def UnCategorizedPageGenerator(total: int = 100, # pragma: no cover
site: OPT_SITE_TYPE = None
) -> Iterable['pywikibot.page.Page']:
@@ -2394,7 +2394,7 @@
return site.uncategorizedpages(total=total)


-@deprecated('Site.uncategorizedtemplates()', since='20200515')
+@deprecated('Site.uncategorizedtemplates()', since='3.0.20200609')
def UnCategorizedTemplateGenerator(total: int = 100, # pragma: no cover
site: OPT_SITE_TYPE = None
) -> Iterable['pywikibot.page.Page']:
@@ -2409,7 +2409,7 @@
return site.uncategorizedtemplates(total=total)


-@deprecated('Site.lonelypages()', since='20200515')
+@deprecated('Site.lonelypages()', since='3.0.20200609')
def LonelyPagesPageGenerator(total: Optional[int] = None, # pragma: no cover
site: OPT_SITE_TYPE = None
) -> Iterable['pywikibot.page.Page']:
@@ -2424,7 +2424,7 @@
return site.lonelypages(total=total)


-@deprecated('Site.unwatchedpages()', since='20200515')
+@deprecated('Site.unwatchedpages()', since='3.0.20200609')
def UnwatchedPagesPageGenerator(total: Optional[int] = None,
site: OPT_SITE_TYPE = None
) -> Iterable['pywikibot.page.Page']:
@@ -2439,7 +2439,7 @@
return site.unwatchedpages(total=total)


-@deprecated('Site.pages_with_property()', since='20200515')
+@deprecated('Site.pages_with_property()', since='3.0.20200609')
def page_with_property_generator(name: str, # pragma: no cover
total: Optional[int] = None,
site: OPT_SITE_TYPE = None
@@ -2470,7 +2470,7 @@
return (page for page, _ in site.ancientpages(total=total))


-@deprecated('Site.deadendpages()', since='20200515')
+@deprecated('Site.deadendpages()', since='3.0.20200609')
def DeadendPagesPageGenerator(total: int = 100, # pragma: no cover
site: OPT_SITE_TYPE = None
) -> Iterable['pywikibot.page.Page']:
@@ -2513,7 +2513,7 @@
return (page for page, _ in site.shortpages(total=total))


-@deprecated('Site.randompages()', since='20200515')
+@deprecated('Site.randompages()', since='3.0.20200609')
def RandomPageGenerator(total: Optional[int] = None, # pragma: no cover
site: OPT_SITE_TYPE = None,
namespaces: Optional[
@@ -2530,7 +2530,7 @@
return site.randompages(total=total, namespaces=namespaces)


-@deprecated('Site.randompages()', since='20200515')
+@deprecated('Site.randompages()', since='3.0.20200609')
def RandomRedirectPageGenerator(total: Optional[int] = None,
site: OPT_SITE_TYPE = None,
namespaces: Optional[
@@ -2548,7 +2548,7 @@
redirects=True)


-@deprecated('Site.exturlusage()', since='20200515')
+@deprecated('Site.exturlusage()', since='3.0.20200609')
def LinksearchPageGenerator(url: str,
namespaces: Optional[List[int]] = None,
total: Optional[int] = None,
@@ -2572,7 +2572,7 @@
total=total, content=False)


-@deprecated('Site.search()', since='20200515')
+@deprecated('Site.search()', since='3.0.20200609')
def SearchPageGenerator(query: str, # pragma: no cover
total: Optional[int] = None,
namespaces: Optional[
diff --git a/pywikibot/site/_apisite.py b/pywikibot/site/_apisite.py
index cc8518a..305dc01 100644
--- a/pywikibot/site/_apisite.py
+++ b/pywikibot/site/_apisite.py
@@ -904,7 +904,7 @@
# return the magic word without the preceding '#' character
return self.getmagicwords('redirect')[0].lstrip('#')

- @deprecated('redirect_regex', since='20210103')
+ @deprecated('redirect_regex', since='5.5.0')
def redirectRegex(self): # noqa: N802
"""Return a compiled regular expression matching on redirect pages."""
return self.redirect_regex
diff --git a/pywikibot/tools/_deprecate.py b/pywikibot/tools/_deprecate.py
index 1c874af..cc36618 100644
--- a/pywikibot/tools/_deprecate.py
+++ b/pywikibot/tools/_deprecate.py
@@ -16,10 +16,10 @@
a deprecator without any arguments.

.. versionchanged:: 6.4
- deprecation decorators moved to _deprecate module
+ deprecation decorators moved to _deprecate submodule
"""
#
-# (C) Pywikibot team, 2008-2021
+# (C) Pywikibot team, 2008-2022
#
# Distributed under the terms of the MIT license.
#
@@ -29,7 +29,6 @@
import sys
import types
from contextlib import suppress
-from datetime import datetime
from importlib import import_module
from inspect import getfullargspec
from typing import Any, Optional
@@ -164,59 +163,41 @@
return outer_wrapper


-def _build_msg_string(instead, since):
+def _build_msg_string(instead: str, since: str) -> str:
"""Build a deprecation warning message format string.

.. versionadded:: 3.0
+
+ .. versionchanged:: 7.0
+ `since`parameter must be a release number, not a timestamp.
+
+ :param instead: suggested replacement for the deprecated object
+ :param since: a version string string when the method was deprecated
"""
- if not since:
- since = ''
- elif '.' in since:
- since = ' since release ' + since
- else:
- year_str = month_str = day_str = ''
- days = (datetime.utcnow() - datetime.strptime(since, '%Y%m%d')).days
- years = days // 365
- days = days % 365
- months = days // 30
- days = days % 30
- if years == 1:
- years = 0
- months += 12
- if years:
- year_str = '{} years'.format(years)
- else:
- day_str = '{} day{}'.format(days, 's' if days != 1 else '')
- if months:
- month_str = '{} month{}'.format(
- months, 's' if months != 1 else '')
- if year_str and month_str:
- year_str += ' and '
- if month_str and day_str:
- month_str += ' and '
- since = ' for {}{}{}'.format(year_str, month_str, day_str)
+ if since and '.' not in since:
+ raise ValueError('{} is not a valid release number'.format(since))
+
if instead:
msg = '{{0}} is deprecated{since}; use {{1}} instead.'
else:
msg = '{{0}} is deprecated{since}.'
- return msg.format(since=since)
+ return msg.format(since=' since release ' + since if since else '')


-def issue_deprecation_warning(name: str, instead=None, depth=2,
- warning_class=None, since=None):
+def issue_deprecation_warning(name: str, instead: str = '', depth: int = 2,
+ warning_class=None, since: str = ''):
"""Issue a deprecation warning.

+ .. versionchanged:: 7.0
+ `since` parameter must be a release number, not a timestamp.
+
:param name: the name of the deprecated object
:param instead: suggested replacement for the deprecated object
- :type instead: str or None
:param depth: depth + 1 will be used as stacklevel for the warnings
- :type depth: int
:param warning_class: a warning class (category) to be used, defaults to
FutureWarning
:type warning_class: type
- :param since: a timestamp string of the date when the method was
- deprecated (form 'YYYYMMDD') or a version string.
- :type since: str or None
+ :param since: a version string string when the method was deprecated
"""
msg = _build_msg_string(instead, since)
if warning_class is None:
@@ -229,10 +210,12 @@
def deprecated(*args, **kwargs):
"""Decorator to output a deprecation warning.

+ .. versionchanged:: 7.0
+ `since` keyword must be a release number, not a timestamp.
+
:keyword instead: if provided, will be used to specify the replacement
:type instead: str
- :keyword since: a timestamp string of the date when the method was
- deprecated (form 'YYYYMMDD') or a version string.
+ :keyword since: a version string string when the method was deprecated
:type since: str
:keyword future_warning: if True a FutureWarning will be thrown,
otherwise it provides a DeprecationWarning
@@ -298,7 +281,7 @@

return wrapper

- since = kwargs.pop('since', None)
+ since = kwargs.pop('since', '')
future_warning = kwargs.pop('future_warning', True)
without_parameters = len(args) == 1 and not kwargs and callable(args[0])
if 'instead' in kwargs:
@@ -509,14 +492,17 @@
target_module: Optional[str] = None,
old_name: Optional[str] = None,
class_name: Optional[str] = None,
- since: Optional[str] = None,
- future_warning=True):
+ since: str = '',
+ future_warning: bool = True):
"""
Return a function which can be used to redirect to 'target'.

It also acts like marking that function deprecated and copies all
parameters.

+ .. versionchanged:: 7.0
+ `since`parameter must be a release number, not a timestamp.
+
:param target: The targeted function which is to be executed.
:type target: callable
:param source_module: The module of the old function. If '.' defaults
@@ -529,11 +515,9 @@
new function.
:param class_name: The name of the class. It's added to the target and
source module (separated by a '.').
- :param since: a timestamp string of the date when the method was
- deprecated (form 'YYYYMMDD') or a version string.
+ :param since: a version string string when the method was deprecated
:param future_warning: if True a FutureWarning will be thrown,
otherwise it provides a DeprecationWarning
- :type future_warning: bool
:return: A new function which adds a warning prior to each execution.
:rtype: callable
"""
@@ -590,11 +574,14 @@
def add_deprecated_attr(self, name: str, replacement: Any = None, *,
replacement_name: Optional[str] = None,
warning_message: Optional[str] = None,
- since: Optional[str] = None,
+ since: str = '',
future_warning: bool = True):
"""
Add the name to the local deprecated names dict.

+ .. versionchanged:: 7.0
+ `since`parameter must be a release number, not a timestamp.
+
:param name: The name of the deprecated class or variable. It may not
be already deprecated.
:param replacement: The replacement value which should be returned
@@ -606,8 +593,7 @@
object name, and evaluated when the deprecated object is needed.
:param warning_message: The warning to display, with positional
variables: {0} = module, {1} = attribute name, {2} = replacement.
- :param since: a timestamp string of the date when the method was
- deprecated (form 'YYYYMMDD') or a version string.
+ :param since: a version string string when the method was deprecated
:param future_warning: if True a FutureWarning will be thrown,
otherwise it provides a DeprecationWarning
"""
diff --git a/scripts/solve_disambiguation.py b/scripts/solve_disambiguation.py
index 88abc43..81d59a6 100755
--- a/scripts/solve_disambiguation.py
+++ b/scripts/solve_disambiguation.py
@@ -665,7 +665,7 @@
issue_deprecation_warning(
'Positional argument {} ({})'.format(i + 1, arg),
'keyword argument "{}={}"'.format(key, arg),
- since='20210303')
+ since='6.0.0')
if key in kwargs:
pywikibot.warning('{!r} is given as keyword argument {!r} '
'already; ignoring {!r}'
@@ -679,7 +679,7 @@
newkey = keymap[key]
issue_deprecation_warning(
'{!r} argument of {}'.format(key, self.__class__.__name__),
- repr(newkey), since='20210303')
+ repr(newkey), since='6.0.0')
kwargs[newkey] = kwargs.pop(key)

# Expand available_options

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I85644fae7864d284b6f908d891d6fc83694302e4
Gerrit-Change-Number: 761391
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki@aol.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged