jenkins-bot merged this change.

View Change

Approvals: Dvorapa: Looks good to me, approved jenkins-bot: Verified
[cleanup] Replace similar codes with a function

- delete _formatLimit_DayOfMonthXX and replace its behavior with
the _format_limit_dom function

Change-Id: I71ee1ddbc2d80d6e06fd2cc00a3386453060c876
---
M pywikibot/date.py
1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/pywikibot/date.py b/pywikibot/date.py
index aecefd1..9ee9d21 100644
--- a/pywikibot/date.py
+++ b/pywikibot/date.py
@@ -2259,19 +2259,23 @@
for month in yrMnthFmts:
formatLimits[month] = _formatLimit_MonthOfYear

-_formatLimit_DayOfMonth31 = (lambda v: 1 <= v and v < 32, 1, 32)
-_formatLimit_DayOfMonth30 = (lambda v: 1 <= v and v < 31, 1, 31)
-_formatLimit_DayOfMonth29 = (lambda v: 1 <= v and v < 30, 1, 30)
+
+def _format_limit_dom(days):
+ """Return day of month format limit."""
+ assert days in range(29, 32)
+ return lambda v: 1 <= v <= days, 1, days + 1
+
+
for monthId in range(12):
if (monthId + 1) in (1, 3, 5, 7, 8, 10, 12):
# 31 days a month
- formatLimits[dayMnthFmts[monthId]] = _formatLimit_DayOfMonth31
+ formatLimits[dayMnthFmts[monthId]] = _format_limit_dom(31)
elif (monthId + 1) == 2: # February
# 29 days a month
- formatLimits[dayMnthFmts[monthId]] = _formatLimit_DayOfMonth29
+ formatLimits[dayMnthFmts[monthId]] = _format_limit_dom(29)
else:
# 30 days a month
- formatLimits[dayMnthFmts[monthId]] = _formatLimit_DayOfMonth30
+ formatLimits[dayMnthFmts[monthId]] = _format_limit_dom(30)


@deprecated('calendar.monthrange', since='20150707')

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I71ee1ddbc2d80d6e06fd2cc00a3386453060c876
Gerrit-Change-Number: 508075
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: jenkins-bot (75)