jenkins-bot submitted this change.

View Change


Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[IMPR] Raise TypeError when argument has wrong type

As suggested in the definition of TypeError itself.

Change-Id: If46449966b926c4063f811af472c42c86db8d991
---
M pywikibot/time.py
1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/pywikibot/time.py b/pywikibot/time.py
index 8a32bfc..4761535 100644
--- a/pywikibot/time.py
+++ b/pywikibot/time.py
@@ -251,7 +251,12 @@
# to create a clone.
if isinstance(ts, cls):
return ts.replace()
- assert isinstance(ts, str)
+
+ if not isinstance(ts, str):
+ raise TypeError(
+ f'ts argument must be a string or a Timestamp object,'
+ f' not {type(ts).__name__}')
+
return cls._from_iso8601(f'{ts[:10]}{sep}{ts[11:]}')

@classmethod
@@ -289,7 +294,12 @@
# to create a clone.
if isinstance(ts, cls):
return ts.replace()
- assert isinstance(ts, str)
+
+ if not isinstance(ts, str):
+ raise TypeError(
+ f'ts argument must be a string or a Timestamp object,'
+ f' not {type(ts).__name__}')
+
if len(ts) == 8 and not strict:
# year, month and day are given only
ts += '000000'

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: If46449966b926c4063f811af472c42c86db8d991
Gerrit-Change-Number: 987450
Gerrit-PatchSet: 1
Gerrit-Owner: Mpaa <mpaa.wiki@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged