New submission from Elian Mariano Gabriel <[email protected]>:
Inside the file calendar.py, there are two functions which are supposed to
calculate the previous and next month relative to the actual year and month.
def _prevmonth(year, month):
if month == 1:
return year-1, 12
else:
return year, month-1
def _nextmonth(year, month):
if month == 12:
return year+1, 1
else:
return year, month+1
Because of the concise calculation that is being made by these functions, it
would be convenient to use the ternary operator to calculate that. So, the
result would be:
def _prevmonth(year, month):
return [year-1, 12] if month == 1 else [year, month-1]
def _nextmonth(year, month):
return [year+1, 1] if month == 12 else [year, month+1]
----------
components: Library (Lib)
files: calendar.py
messages: 381629
nosy: ElianMariano
priority: normal
severity: normal
status: open
title: Use of ternary operator instead of if and else in month calculation
function
versions: Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9
Added file: https://bugs.python.org/file49614/calendar.py
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue42439>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com