jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/987450 )
Change subject: [IMPR] Raise TypeError when argument has wrong type ......................................................................
[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(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
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'