jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/934708 )
Change subject: Revert "[Bugfix] Normalize WbTimes sent to Wikidata"
......................................................................
Revert "[Bugfix] Normalize WbTimes sent to Wikidata"
This reverts commit d335ee732319b466ffd3fe9b1debe3453c4beb4a.
The reason is described in T340495, the underlying issue can be found
in T57755.
Bug: T325860
Bug: T340495
Change-Id: Ia7be04d8932cff0b13f2692c843c282546a82608
---
M pywikibot/__init__.py
M pywikibot/page/_wikibase.py
M tests/wikibase_tests.py
3 files changed, 29 insertions(+), 27 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index e17528f..f8e3564 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -68,7 +68,7 @@
)
from pywikibot.site import APISite, BaseSite, DataSite
from pywikibot.time import Timestamp
-from pywikibot.tools import normalize_username
+from pywikibot.tools import normalize_username, remove_last_args
ItemPageStrNoneType = Union[str, 'ItemPage', None]
@@ -678,8 +678,8 @@
kwargs['second'] = self.second
return type(self)(**kwargs)
- def toTimestr(self, force_iso: bool = False,
- normalize: bool = False) -> str:
+ @remove_last_args(['normalize']) # since 8.2.0
+ def toTimestr(self, force_iso: bool = False) -> str:
"""Convert the data to a UTC date/time string.
.. seealso:: :meth:`fromTimestr` for differences between output
@@ -687,15 +687,13 @@
.. versionchanged:: 8.0
*normalize* parameter was added.
+ .. versionchanged:: 8.2
+ *normalize* parameter was removed due to :phab:`T340495` and
+ :phab:`57755`
:param force_iso: whether the output should be forced to ISO 8601
- :param normalize: whether the output should be normalized (see
- :meth:`normalize` for details)
:return: Timestamp in a format resembling ISO 8601
"""
- if normalize:
- return self.normalize().toTimestr(force_iso=force_iso,
- normalize=False)
if force_iso:
return Timestamp._ISO8601Format_new.format(
self.year, max(1, self.month), max(1, self.day),
@@ -724,17 +722,19 @@
datetime.timedelta(minutes=self.timezone)))
return ts
- def toWikibase(self, normalize: bool = False) -> Dict[str, Any]:
+ @remove_last_args(['normalize']) # since 8.2.0
+ def toWikibase(self) -> Dict[str, Any]:
"""Convert the data to a JSON object for the Wikibase API.
.. versionchanged:: 8.0
*normalize* parameter was added.
+ .. versionchanged:: 8.2
+ *normalize* parameter was removed due to :phab:`T340495` and
+ :phab:`57755`
- :param normalize: Whether to normalize the WbTime object before
- converting it to a JSON object (see :func:`normalize` for details)
:return: Wikibase JSON
"""
- json = {'time': self.toTimestr(normalize=normalize),
+ json = {'time': self.toTimestr(),
'precision': self.precision,
'after': self.after,
'before': self.before,
diff --git a/pywikibot/page/_wikibase.py b/pywikibot/page/_wikibase.py
index 5f7ef6b..7b341cb 100644
--- a/pywikibot/page/_wikibase.py
+++ b/pywikibot/page/_wikibase.py
@@ -1952,9 +1952,6 @@
def _formatValue(self) -> dict:
"""Format the target into the proper JSON value that Wikibase
wants.
- .. versionchanges:: 8.0
- normalize the result if type is ``time``.
-
:return: JSON value
"""
# todo: eventually unify the following two groups
@@ -1970,9 +1967,7 @@
value = self.getTarget()
elif self.type == 'commonsMedia':
value = self.getTarget().title(with_ns=False)
- elif self.type == 'time':
- value = self.getTarget().toWikibase(normalize=False)
- elif self.type in ('globe-coordinate',
+ elif self.type in ('globe-coordinate', 'time',
'quantity', 'monolingualtext',
'geo-shape', 'tabular-data'):
value = self.getTarget().toWikibase()
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index ea322ed..549a49d 100755
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -285,15 +285,6 @@
self.assertEqual(t.toTimestr(), '-00000002010-01-01T12:43:00Z')
self.assertEqual(t.toTimestr(force_iso=True), '-2010-01-01T12:43:00Z')
- t = pywikibot.WbTime(site=repo, year=2010, hour=12, minute=43,
- precision=pywikibot.WbTime.PRECISION['day'])
- self.assertEqual(t.toTimestr(), '+00000002010-01-01T12:43:00Z')
- self.assertEqual(t.toTimestr(force_iso=True), '+2010-01-01T12:43:00Z')
- self.assertEqual(t.toTimestr(normalize=True),
- '+00000002010-01-01T00:00:00Z')
- self.assertEqual(t.toTimestr(force_iso=True, normalize=True),
- '+2010-01-01T00:00:00Z')
-
def test_WbTime_fromTimestr(self):
"""Test WbTime creation from UTC date/time
string."""
repo = self.get_repo()
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/934708
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: Ia7be04d8932cff0b13f2692c843c282546a82608
Gerrit-Change-Number: 934708
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Multichill <maarten(a)mdammers.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged