jenkins-bot has submitted this change and it was merged.
Change subject: PEP8 and PEP257 fixes ......................................................................
PEP8 and PEP257 fixes
tox.ini excluded date.py.
All PEP8 problems fixed, and all lines now under 90 chars.
All PEP257 except for D102 & D103 now also fixed.
Bug: T87169 Change-Id: If5eb2fee6c6d3db82c946155e7b492a9e0290cbc --- M pywikibot/date.py M tox.ini 2 files changed, 60 insertions(+), 41 deletions(-)
Approvals: XZise: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/date.py b/pywikibot/date.py index 36dc254..1bdd05e 100644 --- a/pywikibot/date.py +++ b/pywikibot/date.py @@ -186,7 +186,7 @@
def slh(value, lst): - """This function helps in simple list value matching. + """Helper function for simple list value matching.
!!!!! The index starts at 1, so 1st element has index 1, not 0 !!!!!
@@ -212,7 +212,7 @@
def dh_constVal(value, ind, match): - """This function helps with matching a single value to a constant. + """Helper function to match a single value to a constant.
formats['CurrEvents']['en'](ind) => u'Current Events' formats['CurrEvents']['en'](u'Current Events') => ind @@ -331,7 +331,7 @@ 'G': (_guDigits, lambda v: intToLocalDigitsStr(v, _guDigitsToLocal), lambda v: localDigitsStrToInt(v, _guDigitsToLocal, _guLocalToDigits)), # %T is a year in TH: -- all years are shifted: 2005 => 'พ.ศ. 2548' - 'T': (_decimalDigits, lambda v: unicode(v+543), lambda v: int(v)-543), + 'T': (_decimalDigits, lambda v: unicode(v + 543), lambda v: int(v) - 543), }
# Allows to search for '(%%)|(%d)|(%R)|...", and allows one digit 1-9 to set @@ -353,7 +353,6 @@ Allows matching of any _digitDecoders inside the string. Returns a compiled regex object and a list of digit decoders. """ - if pattern not in _escPtrnCache2: newPattern = u'^' # begining of the string strPattern = u'' @@ -402,7 +401,7 @@
def dh(value, pattern, encf, decf, filter=None): - """This function helps in year parsing. + """Function to help with year parsing.
Usually it will be used as a lambda call in a map::
@@ -427,7 +426,6 @@ numeral number.
""" - compPattern, strPattern, decoders = escapePattern2(pattern) if isinstance(value, basestring): m = compPattern.match(value) @@ -479,7 +477,7 @@ # force parameter length by taking the first digit in the list and # repeating it required number of times # This converts "205" into "0205" for "%4d" - newValue = decoder[0][0] * (decoder[3]-len(newValue)) + newValue + newValue = decoder[0][0] * (decoder[3] - len(newValue)) + newValue return newValue
# @@ -1002,7 +1000,7 @@ 'su': dh_simpleYearAD, 'ta': dh_simpleYearAD, 'te': dh_simpleYearAD, - #2005 => 'พ.ศ. 2548' + # 2005 => 'พ.ศ. 2548' 'th': lambda v: dh_yearAD(v, u'พ.ศ. %T'), 'tl': dh_simpleYearAD, 'tpi': dh_simpleYearAD, @@ -1163,18 +1161,18 @@ # 1970s => 'Decennium 198' (1971-1980) 'la': lambda v: dh(v, u'Decennium %d', lambda i: encDec1(i) // 10 + 1, - lambda ii: (ii[0]-1) * 10), + lambda ii: (ii[0] - 1) * 10),
# 1970s => 'XX amžiaus 8-as dešimtmetis' (1971-1980) 'lt': lambda v: dh(v, u'%R amžiaus %d-as dešimtmetis', lambda i: (encDec1(i) // 100 + 1, encDec1(i) % 100 // 10 + 1), - lambda v: (v[0]-1)*100 + (v[1]-1)*10), + lambda v: (v[0] - 1) * 100 + (v[1] - 1) * 10),
# 1970s => 'Ngahurutanga 198' (1971-1980) 'mi': lambda v: dh(v, u'Ngahurutanga %d', lambda i: encDec0(i) // 10 + 1, - lambda ii: (ii[0]-1) * 10), + lambda ii: (ii[0] - 1) * 10),
'mhr': lambda v: dh_decAD(v, u'%d ийла'),
@@ -1196,7 +1194,7 @@ lambda p: p % 100 >= 0 and p % 100 < 20), (lambda v: dh(v, u'Lata %d. %R wieku', lambda i: (encDec0(i) % 100, encDec0(i) // 100 + 1), - lambda ii: (ii[1]-1)*100 + ii[0]), + lambda ii: (ii[1] - 1) * 100 + ii[0]), alwaysTrue)]), 'pt': lambda v: dh_decAD(v, u'Década de %d'), 'ro': lambda v: dh_decAD(v, u'Anii %d'), @@ -1211,7 +1209,7 @@ # 1970 => '70. roky 20. storočia' 'sk': lambda v: dh(v, u'%d. roky %d. storočia', lambda i: (encDec0(i) % 100, encDec0(i) // 100 + 1), - lambda ii: (ii[1]-1) * 100 + ii[0]), + lambda ii: (ii[1] - 1) * 100 + ii[0]),
'sl': lambda v: dh_decAD(v, u'%d.'), 'sq': lambda v: dh_decAD(v, u'Vitet %d'), @@ -1259,7 +1257,8 @@ (lambda v: dh_decBC(v, u'i. e. %d-es évek'), alwaysTrue)]), 'it': lambda v: dh_decBC(v, u'Anni %d a.C.'), 'ka': lambda v: dh_decBC(v, u'ძვ. წ. %d-ები'), - 'ksh': lambda v: dh_decBC(v, u'%d-er Joohre füür Krėßtůß'), # uncertain if that's right. might go to redirect. + 'ksh': lambda v: dh_decBC(v, u'%d-er Joohre füür Krėßtůß'), + # uncertain if ksh is right. might go to redirect.
# '19-10 v. Chr.' 'nl': lambda m: multi(m, [ @@ -1483,7 +1482,8 @@ 'ja': lambda v: dh_centuryBC(v, u'紀元前%d世紀'), 'ka': lambda v: dh_centuryBC(v, u'ძვ. წ. %R საუკუნე'), 'ko': lambda v: dh_centuryBC(v, u'기원전 %d세기'), - 'ksh': lambda v: dh_centuryBC(v, u'%d. Joohunndot füür Kreůßtůß'), # uncertain if that's right. might go to redirect. + 'ksh': lambda v: dh_centuryBC(v, u'%d. Joohunndot füür Kreůßtůß'), + # uncertain if ksh is right. might go to redirect. 'la': lambda v: dh_centuryBC(v, u'Saeculum %d a.C.n.'), 'lb': lambda v: dh_centuryBC(v, u'%d. Joerhonnert v. Chr.'), 'nl': lambda v: dh_centuryBC(v, u'%de eeuw v.Chr.'), @@ -1519,14 +1519,14 @@ 'cs': lambda v: dh_centuryAD(v, u'%d. století'), 'da': lambda v: dh_centuryAD(v, u'%d. århundrede'), 'no': lambda v: dh(v, u'%d-tallet', - lambda i: (i-1) * 100, lambda ii: ii[0] // 100 + 1), + lambda i: (i - 1) * 100, lambda ii: ii[0] // 100 + 1), },
'CenturyBC_Cat': { 'cs': lambda v: dh_centuryBC(v, u'%d. století př. n. l.'), 'de': lambda v: dh_centuryBC(v, u'Jahr (%d. Jh. v. Chr.)'), 'no': lambda v: dh(v, u'%d-tallet f.Kr.', - lambda i: (i-1) * 100, lambda ii: ii[0] // 100 + 1), + lambda i: (i - 1) * 100, lambda ii: ii[0] // 100 + 1), },
'MillenniumAD': { @@ -1559,7 +1559,9 @@ (lambda v: dh_constVal(v, 5, u'Viides vuosituhat'), lambda p: p == 5), (lambda v: dh(v, u'%d000-vuosituhat', - lambda i: i - 1, lambda ii: ii[0]+1), alwaysTrue)]), + lambda i: i - 1, + lambda ii: ii[0] + 1), + alwaysTrue)]),
'fr': lambda m: multi(m, [ (lambda v: dh_millenniumAD(v, u'%Rer millénaire'), @@ -1992,10 +1994,10 @@ u"%d d'abril", u"%d de mayo", u"%d de chunio", u"%d de chulio", u"%d d'agosto", u"%d de setiembre", u"%d d'otubre", u"%d de nobiembre", u"%d d'abiento"]) -##addFmt1('ang',False, [u"%d Æfterra Gēola", u"%d Solmōnaþ", u"%d Hréþmónaþ", -## u"%d Éastermónaþ", u"%d Þrimilcemónaþ", u"%d Séremónaþ", -## u"%d Mǽdmónaþ", u"%d Wéodmónaþ", u"%d Háligmónaþ", -## u"%d Winterfylleþ", u"%d Blótmónaþ", u"%d Gēolmōnaþ"]) +# addFmt1('ang',False, [u"%d Æfterra Gēola", u"%d Solmōnaþ", u"%d Hréþmónaþ", +# u"%d Éastermónaþ", u"%d Þrimilcemónaþ", u"%d Séremónaþ", +# u"%d Mǽdmónaþ", u"%d Wéodmónaþ", u"%d Háligmónaþ", +# u"%d Winterfylleþ", u"%d Blótmónaþ", u"%d Gēolmōnaþ"]) addFmt2('ang', False, u"%%d %s", True) addFmt1('ar', False, [u"%d يناير", u"%d فبراير", u"%d مارس", u"%d أبريل", u"%d مايو", u"%d يونيو", u"%d يوليو", u"%d أغسطس", @@ -2009,7 +2011,7 @@ u"%d ліпеня", u"%d жніўня", u"%d верасьня", u"%d кастрычніка", u"%d лістапада", u"%d сьнежня"]) addFmt2('bg', False, u"%%d %s", False) -##addFmt2('br', False, u"%%d %s", True) # See bellow for br initialization +# addFmt2('br', False, u"%%d %s", True) # See bellow for br initialization addFmt2('bn', False, u"%s %%B") addFmt2('bs', False, u"%%d. %s", False) addFmt1('ca', False, [u"%d de gener", u"%d de febrer", u"%d de març", @@ -2052,7 +2054,10 @@ u"%d Lúnasa", u"%d Meán Fómhair", u"%d Deireadh Fómhair", u"%d Samhain", u"%d Mí na Nollag"]) addFmt2('gl', False, u"%%d de %s", False) -addFmt2('he', False, u"%%d ב%s") # [u"%d בינואר", u"%d בפברואר", u"%d במרץ", u"%d באפריל", u"%d במאי", u"%d ביוני", u"%d ביולי", u"%d באוגוסט", u"%d בספטמבר", u"%d באוקטובר", u"%d בנובמבר", u"%d בדצמבר"]) +addFmt2('he', False, u"%%d ב%s") +# [u"%d בינואר", u"%d בפברואר", u"%d במרץ", u"%d באפריל", u"%d במאי", +# u"%d ביוני", u"%d ביולי", u"%d באוגוסט", u"%d בספטמבר", u"%d באוקטובר", +# u"%d בנובמבר", u"%d בדצמבר"]) addFmt1('hr', False, [u"%d. siječnja", u"%d. veljače", u"%d. ožujka", u"%d. travnja", u"%d. svibnja", u"%d. lipnja", u"%d. srpnja", u"%d. kolovoza", u"%d. rujna", @@ -2248,23 +2253,34 @@
# This table defines the limits for each type of format data. -# Each item is a tuple with a predicate function -# (returns True if the value falls within acceptable limits, False otherwise), -# In addition, tuple contains start, end, and step values that will be used to -# test the formats table for internal consistency. +# Each item is a tuple with +# - a predicate function which returns True if the value falls +# within acceptable limits, False otherwise, +# - start value +# - end value +# +# TODO: Before compat 19d1cf9e (2006), there was a 'step' in the tuple, +# used exclusively by DecadeAD and DecadeBC to increment by 10 years. +# "and v%10==0" should be added to the limitation predicate for those two. formatLimits = { 'MonthName': (lambda v: 1 <= v and v < 13, 1, 13), 'Number': (lambda v: 0 <= v and v < 1000000, 0, 1001), 'YearAD': (lambda v: 0 <= v and v < 2501, 0, 2501), 'YearBC': (lambda v: 0 <= v and v < 4001, 0, 501), # zh: has years as old as 前1700年 - 'DecadeAD': (lambda v: 0 <= v and v < 2501, 0, 2501), # At some point need to re-add "and v%10==0" to the limitation + 'DecadeAD': (lambda v: 0 <= v and v < 2501, 0, 2501), 'DecadeBC': (lambda v: 0 <= v and v < 4001, 0, 501), # zh: has decades as old as 前1700年代 - 'CenturyAD': (lambda v: 1 <= v and v < 41, 1, 23), # Some centuries use Roman numerals or a given list - do not exceed them in testing - 'CenturyBC': (lambda v: 1 <= v and v < 91, 1, 23), # Some centuries use Roman numerals or a given list - do not exceed them in testing - 'MillenniumAD': (lambda v: 1 <= v and v < 6, 1, 4), # For millenniums, only test first 3 AD Millenniums, - 'MillenniumBC': (lambda v: 1 <= v and v < 20, 1, 2), # And only 1 BC Millennium - 'CenturyAD_Cat': (lambda v: 1 <= v and v < 41, 1, 23), # Some centuries use Roman numerals or a given list - do not exceed them in testing - 'CenturyBC_Cat': (lambda v: 1 <= v and v < 41, 1, 23), # Some centuries use Roman numerals or a given list - do not exceed them in testing + + # Some centuries use Roman numerals or a given list + # do not exceed them in testing + 'CenturyAD': (lambda v: 1 <= v and v < 41, 1, 23), + 'CenturyBC': (lambda v: 1 <= v and v < 91, 1, 23), + 'CenturyAD_Cat': (lambda v: 1 <= v and v < 41, 1, 23), + 'CenturyBC_Cat': (lambda v: 1 <= v and v < 41, 1, 23), + + # For millenniums, only test first 3 AD Millenniums and 1 BC Millennium + 'MillenniumAD': (lambda v: 1 <= v and v < 6, 1, 4), + 'MillenniumBC': (lambda v: 1 <= v and v < 20, 1, 2), + 'Cat_Year_MusicAlbums': (lambda v: 1950 <= v and v < 2021, 1950, 2021), 'Cat_BirthsAD': (lambda v: 0 <= v and v < 2501, 0, 2501), 'Cat_DeathsAD': (lambda v: 0 <= v and v < 2501, 0, 2501), @@ -2285,7 +2301,7 @@ if (monthId + 1) in (1, 3, 5, 7, 8, 10, 12): # 31 days a month formatLimits[dayMnthFmts[monthId]] = _formatLimit_DayOfMonth31 - elif (monthId+1) == 2: # February + elif (monthId + 1) == 2: # February # 29 days a month formatLimits[dayMnthFmts[monthId]] = _formatLimit_DayOfMonth29 else: @@ -2295,7 +2311,7 @@
def getNumberOfDaysInMonth(month): """Return the number of days in a given month, 1 being January, etc.""" - return formatLimits[dayMnthFmts[month-1]][2]-1 + return formatLimits[dayMnthFmts[month - 1]][2] - 1
def getAutoFormat(lang, title, ignoreFirstLetterCase=True): @@ -2330,11 +2346,15 @@
class FormatDate(object):
+ """Format a date.""" + def __init__(self, site): + """Constructor.""" self.site = site
def __call__(self, m, d): - return formats['Day_' + enMonthNames[m-1]][self.site.lang](d) + """Return a formatted month and day.""" + return formats['Day_' + enMonthNames[m - 1]][self.site.lang](d)
def formatYear(lang, year): diff --git a/tox.ini b/tox.ini index ae60d99..94b26dd 100644 --- a/tox.ini +++ b/tox.ini @@ -44,7 +44,6 @@ pywikibot/config2.py \ pywikibot/data/__init__.py \ pywikibot/data/wikistats.py \ - pywikibot/date.py \ pywikibot/diff.py \ pywikibot/echo.py \ pywikibot/editor.py \ @@ -132,11 +131,11 @@
[flake8] ignore = E122,E127,E241,E265 -exclude = .tox,.git,./*.egg,ez_setup.py,build,externals,user-config.py,./scripts/i18n/*,./pywikibot/date.py +exclude = .tox,.git,./*.egg,ez_setup.py,build,externals,user-config.py,./scripts/i18n/* max_line_length = 200
[pep8] ignore = E122,E127,E241 -exclude = .tox,.git,./*.egg,ez_setup.py,build,externals,user-config.py,./scripts/i18n/*,./pywikibot/date.py +exclude = .tox,.git,./*.egg,ez_setup.py,build,externals,user-config.py,./scripts/i18n/* max_line_length = 200
pywikibot-commits@lists.wikimedia.org