jenkins-bot submitted this change.
[IMPR] Deprecate Timestamp.clone() method
- Timestamp.clone was introduced to unnecessaryly call replace() method
with microseconds parameter but replace() already uses self.microseconds
if this parameter was not given (refer Python's documentation). Deprecate
this method and use relace() method instead.
- remove test_clone() test method. clone() is an alias for replace() now
and it is not necessary to test the Python library.
Change-Id: Idbb52a6f9336b8bb194a45c70fc92eb322a552ff
---
M tests/time_tests.py
M pywikibot/time.py
2 files changed, 30 insertions(+), 16 deletions(-)
diff --git a/pywikibot/time.py b/pywikibot/time.py
index 42d8294..d02d53f 100644
--- a/pywikibot/time.py
+++ b/pywikibot/time.py
@@ -3,7 +3,7 @@
.. versionadded:: 7.5
"""
#
-# (C) Pywikibot team, 2007-2022
+# (C) Pywikibot team, 2007-2023
#
# Distributed under the terms of the MIT license.
#
@@ -16,7 +16,7 @@
import pywikibot
from pywikibot.backports import Tuple
-from pywikibot.tools import classproperty
+from pywikibot.tools import classproperty, deprecated
__all__ = (
@@ -211,9 +211,14 @@
raise ValueError(f'time data {timestr!r} does not match any format.')
+ @deprecated('replace method', since='8.0.0')
def clone(self) -> 'Timestamp':
- """Clone this instance."""
- return self.replace(microsecond=self.microsecond)
+ """Clone this instance.
+
+ .. deprecated:: 8.0
+ Use :meth:`replace` method instead.
+ """
+ return self.replace()
@classproperty
def ISO8601Format(cls: Type['Timestamp']) -> str: # noqa: N802
@@ -244,9 +249,9 @@
# If inadvertently passed a Timestamp object, use replace()
# to create a clone.
if isinstance(ts, cls):
- return ts.clone()
- _ts = f'{ts[:10]}{sep}{ts[11:]}'
- return cls._from_iso8601(_ts)
+ return ts.replace()
+
+ return cls._from_iso8601(f'{ts[:10]}{sep}{ts[11:]}')
@classmethod
def fromtimestampformat(cls: Type['Timestamp'],
@@ -282,7 +287,7 @@
# If inadvertently passed a Timestamp object, use replace()
# to create a clone.
if isinstance(ts, cls):
- return ts.clone()
+ return ts.replace()
if len(ts) == 8 and not strict:
# year, month and day are given only
diff --git a/tests/time_tests.py b/tests/time_tests.py
index 7d4f8d8..c074b7e 100755
--- a/tests/time_tests.py
+++ b/tests/time_tests.py
@@ -1,7 +1,7 @@
#!/usr/bin/python3
"""Tests for the Timestamp class."""
#
-# (C) Pywikibot team, 2014-2022
+# (C) Pywikibot team, 2014-2023
#
# Distributed under the terms of the MIT license.
#
@@ -115,13 +115,6 @@
self.assertRaisesRegex(ValueError, regex):
Timestamp.set_timestamp(timestr)
- def test_clone(self):
- """Test cloning a Timestamp instance."""
- t1 = Timestamp.utcnow()
- t2 = t1.clone()
- self.assertEqual(t1, t2)
- self.assertIsInstance(t2, Timestamp)
-
def test_instantiate_from_instance(self):
"""Test passing instance to factory methods works."""
t1 = Timestamp.utcnow()
To view, visit change 871888. To unsubscribe, or for help writing mail filters, visit settings.