jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/403906 )
Change subject: [cleanup] use assert instead of raising AssertionError ...................................................................... [cleanup] use assert instead of raising AssertionError Change-Id: I9ae1af2cb2557169239052a3bb5f7b23e6283fb1 --- M pywikibot/date.py M pywikibot/page.py 2 files changed, 22 insertions(+), 26 deletions(-) Approvals: Framawiki: Looks good to me, approved jenkins-bot: Verified diff --git a/pywikibot/date.py b/pywikibot/date.py index b6c45ab..bf01478 100644 --- a/pywikibot/date.py +++ b/pywikibot/date.py @@ -7,7 +7,7 @@ # (C) Andre Engels, 2004-2005 # (C) Yuri Astrakhan, 2005-2006 (<Firstname><Lastname>@gmail.com) # (years/decades/centuries/millenniums str <=> int conversions) -# (C) Pywikibot team, 2004-2017 +# (C) Pywikibot team, 2004-2018 # # Distributed under the terms of the MIT license. # @@ -384,10 +384,9 @@ if isinstance(dec, basestring): # Special case for strings that are replaced instead of # decoded - if len(s) == 3: - raise AssertionError( - "Invalid pattern %s: Cannot use zero padding size " - "in %s!" % (pattern, s)) + assert len(s) < 3, ( + 'Invalid pattern {0}: Cannot use zero padding size ' + 'in {1}!'.format(pattern, s)) newPattern += re.escape(dec) strPattern += s # Keep the original text else: @@ -451,8 +450,8 @@ for i in range(len(decoders))] decValue = decf(values) - if isinstance(decValue, basestring): - raise AssertionError("Decoder must not return a string!") + assert not isinstance(decValue, basestring), \ + 'Decoder must not return a string!' # recursive call to re-encode and see if we get the original # (may through filter exception) @@ -473,19 +472,17 @@ MakeParameter = _make_parameter if type(params) in _listTypes: - if len(params) != len(decoders): - raise AssertionError( - "parameter count (%d) does not match decoder count (%d)" - % (len(params), len(decoders))) + assert len(params) == len(decoders), ( + 'parameter count ({0}) does not match decoder count ({1})' + .format(len(params), len(decoders))) # convert integer parameters into their textual representation params = [MakeParameter(decoders[i], params[i]) for i in range(len(params))] return strPattern % tuple(params) else: - if 1 != len(decoders): - raise AssertionError( - "A single parameter does not match %d decoders." - % len(decoders)) + assert len(decoders) == 1, ( + 'A single parameter does not match {0} decoders.' + .format(len(decoders))) # convert integer parameter into its textual representation return strPattern % MakeParameter(decoders[0], params) @@ -1959,15 +1956,16 @@ def addFmt1(lang, isMnthOfYear, patterns): - """Add 12 month formats for a specific type ('January','Feb..), for a given language. + """Add 12 month formats for a specific type ('January', 'Feb.'). The function must accept one parameter for the ->int or ->string conversions, just like everywhere else in the formats map. The patterns parameter is a list of 12 elements to be used for each month. + @param lang: language code + @type lang: str """ - if len(patterns) != 12: - raise AssertionError(u'pattern %s does not have 12 elements' % lang) + assert len(patterns) == 12, 'pattern %s does not have 12 elements' % lang for i in range(12): if patterns[i] is not None: diff --git a/pywikibot/page.py b/pywikibot/page.py index 6cff93b..22438fd 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -5219,10 +5219,9 @@ @rtype: int or long @raises AssertionError: parent id not supplied to the constructor """ - if self._parent_id is None: - raise AssertionError( - 'Revision %d was instantiated without a parent id' - % self.revid) + assert self._parent_id is not None, ( + 'Revision {0} was instantiated without a parent id' + .format(self.revid)) return self._parent_id @@ -5237,10 +5236,9 @@ which always occurs for MediaWiki versions lower than 1.21. """ # TODO: T102735: Add a sane default of 'wikitext' and others for <1.21 - if self._content_model is None: - raise AssertionError( - 'Revision %d was instantiated without a content model' - % self.revid) + assert self._content_model is not None, ( + 'Revision {0} was instantiated without a content model' + .format(self.revid)) return self._content_model -- To view, visit https://gerrit.wikimedia.org/r/403906 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-MessageType: merged Gerrit-Change-Id: I9ae1af2cb2557169239052a3bb5f7b23e6283fb1 Gerrit-Change-Number: 403906 Gerrit-PatchSet: 5 Gerrit-Owner: Xqt <i...@gno.de> Gerrit-Reviewer: Dalba <dalba.w...@gmail.com> Gerrit-Reviewer: Framawiki <framaw...@tools.wmflabs.org> Gerrit-Reviewer: John Vandenberg <jay...@gmail.com> Gerrit-Reviewer: Xqt <i...@gno.de> Gerrit-Reviewer: Zoranzoki21 <zorandori4...@gmail.com> Gerrit-Reviewer: jenkins-bot <>
_______________________________________________ Pywikibot-commits mailing list Pywikibot-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits