https://github.com/python/cpython/commit/4924bcf0e4f46f61ac806a90192393f915d0f8f9
commit: 4924bcf0e4f46f61ac806a90192393f915d0f8f9
branch: main
author: Stan Ulbrych <89152624+stanfromirel...@users.noreply.github.com>
committer: hugovk <1324225+hug...@users.noreply.github.com>
date: 2025-04-24T17:16:07+03:00
summary:

gh-89157: Make C and Python implementation of `datetime.date.fromisoformat` 
consistent (#131007)

files:
A Misc/NEWS.d/next/Library/2025-03-09-10-37-00.gh-issue-89157.qg3r138.rst
M Lib/_pydatetime.py
M Lib/test/datetimetester.py

diff --git a/Lib/_pydatetime.py b/Lib/_pydatetime.py
index 50e21a12335611..e3db1b52b1159b 100644
--- a/Lib/_pydatetime.py
+++ b/Lib/_pydatetime.py
@@ -1050,8 +1050,12 @@ def fromordinal(cls, n):
     @classmethod
     def fromisoformat(cls, date_string):
         """Construct a date from a string in ISO 8601 format."""
+
         if not isinstance(date_string, str):
-            raise TypeError('fromisoformat: argument must be str')
+            raise TypeError('Argument must be a str')
+
+        if not date_string.isascii():
+            raise ValueError('Argument must be an ASCII str')
 
         if len(date_string) not in (7, 8, 10):
             raise ValueError(f'Invalid isoformat string: {date_string!r}')
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
index ecb37250ceb6c4..55844ec35a90c9 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -2087,6 +2087,7 @@ def test_fromisoformat_fails(self):
             '10000-W25-1',      # Invalid year
             '2020-W25-0',       # Invalid day-of-week
             '2020-W25-8',       # Invalid day-of-week
+            '٢025-03-09'        # Unicode characters
             '2009\ud80002\ud80028',     # Separators are surrogate codepoints
         ]
 
@@ -3542,7 +3543,7 @@ def test_fromisoformat_fails_datetime(self):
             '2009-04-19T03:15:4500:00',     # Bad time zone separator
             '2009-04-19T03:15:45.123456+24:30',    # Invalid time zone offset
             '2009-04-19T03:15:45.123456-24:30',    # Invalid negative offset
-            '2009-04-10ᛇᛇᛇᛇᛇ12:15',         # Too many unicode separators
+            '2009-04-10ᛇᛇᛇᛇᛇ12:15',         # Unicode chars
             '2009-04\ud80010T12:15',        # Surrogate char in date
             '2009-04-10T12\ud80015',        # Surrogate char in time
             '2009-04-19T1',                 # Incomplete hours
diff --git 
a/Misc/NEWS.d/next/Library/2025-03-09-10-37-00.gh-issue-89157.qg3r138.rst 
b/Misc/NEWS.d/next/Library/2025-03-09-10-37-00.gh-issue-89157.qg3r138.rst
new file mode 100644
index 00000000000000..0031721f89b719
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-03-09-10-37-00.gh-issue-89157.qg3r138.rst
@@ -0,0 +1,2 @@
+Make the pure Python implementation of :func:`datetime.date.fromisoformat`,
+only accept ASCII strings for consistency with the C implementation.

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to