[Python-checkins] gh-103822: [Calendar] change return value to enum for day and month APIs (GH-103827)

ethanfurman webhook-mailer at python.org
Tue May 2 16:13:39 EDT 2023


https://github.com/python/cpython/commit/1f5384434dce013b5dcf7e7ea3ec5312d13bba72
commit: 1f5384434dce013b5dcf7e7ea3ec5312d13bba72
branch: main
author: Prince Roshan <princekrroshan01 at gmail.com>
committer: ethanfurman <ethan at stoneleaf.us>
date: 2023-05-02T13:13:31-07:00
summary:

gh-103822: [Calendar] change return value to enum for day and month APIs (GH-103827)

files:
A Misc/NEWS.d/next/Library/2023-05-02-04-49-45.gh-issue-103822.m0QdAO.rst
M Lib/calendar.py

diff --git a/Lib/calendar.py b/Lib/calendar.py
index bbd4fea3b88c..ea56f12ccc41 100644
--- a/Lib/calendar.py
+++ b/Lib/calendar.py
@@ -83,7 +83,6 @@ class Day(IntEnum):
     SUNDAY = 6
 
 
-
 # Number of days per month (except for February in leap years)
 mdays = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
 
@@ -156,7 +155,7 @@ def weekday(year, month, day):
     """Return weekday (0-6 ~ Mon-Sun) for year, month (1-12), day (1-31)."""
     if not datetime.MINYEAR <= year <= datetime.MAXYEAR:
         year = 2000 + year % 400
-    return datetime.date(year, month, day).weekday()
+    return Day(datetime.date(year, month, day).weekday())
 
 
 def monthrange(year, month):
diff --git a/Misc/NEWS.d/next/Library/2023-05-02-04-49-45.gh-issue-103822.m0QdAO.rst b/Misc/NEWS.d/next/Library/2023-05-02-04-49-45.gh-issue-103822.m0QdAO.rst
new file mode 100644
index 000000000000..3daf9cc09380
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-05-02-04-49-45.gh-issue-103822.m0QdAO.rst
@@ -0,0 +1 @@
+Update the return type of ``weekday`` to the newly added Day attribute



More information about the Python-checkins mailing list