Skip to content

gh-83461: Don't allow datetime parsing to accept non-ASCII digits #131008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c20c6da
Initial
StanFromIreland Mar 9, 2025
decd90f
Fix NEWS
StanFromIreland Mar 9, 2025
81276eb
sggestion
StanFromIreland Mar 9, 2025
0a3e67b
Alphabetical order…
StanFromIreland Mar 9, 2025
5d1d53d
Benedikts suggestions
StanFromIreland Mar 9, 2025
a0b0f07
Add docs and tests for time.strptime
StanFromIreland Mar 9, 2025
d0e6a1f
Cover the majority
StanFromIreland Mar 10, 2025
2f6d8e2
Cover all
StanFromIreland Mar 10, 2025
ccabadf
Clean up
StanFromIreland Mar 10, 2025
35bc090
Benedikt's Doc suggestions
StanFromIreland Mar 12, 2025
0637c29
Apply suggestions from code review
StanFromIreland Mar 15, 2025
71d7c8a
Re-word news
StanFromIreland Mar 15, 2025
212c763
Apply suggestions from code review
StanFromIreland Mar 15, 2025
0201347
PEP 8
StanFromIreland Mar 15, 2025
bebb241
REQUESTED CHANGES
StanFromIreland Mar 23, 2025
40d2368
Refactor documentation changes
pganssle Mar 26, 2025
77c936a
Clarify non-ASCII parsing in news
pganssle Mar 26, 2025
e652581
fixup! Refactor documentation changes
pganssle Mar 26, 2025
0115ee4
Unrequire ascii
StanFromIreland Mar 26, 2025
25a6705
Merge branch 'main' into ascii-strptime
StanFromIreland Apr 24, 2025
3bca8e9
Merge branch 'main' into ascii-strptime
pganssle May 19, 2025
ddd1d01
Adjust documentation to be specific about where non-ASCII digits are …
pganssle May 19, 2025
0139e57
Move whatsnew
StanFromIreland May 19, 2025
be40130
Merge branch 'main' into ascii-strptime
StanFromIreland Jun 25, 2025
f4c4751
Fixup merge
StanFromIreland Jun 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Lib/_strptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import time
import locale
import calendar
from re import A as re_A
from re import compile as re_compile
from re import sub as re_sub
from re import IGNORECASE
Expand Down Expand Up @@ -380,7 +381,7 @@ def repl(m):

def compile(self, format):
"""Return a compiled re object for the format string."""
return re_compile(self.pattern(format), IGNORECASE)
return re_compile(self.pattern(format), IGNORECASE | re_A)

_cache_lock = _thread_allocate_lock()
# DO NOT modify _TimeRE_cache or _regex_cache without acquiring the cache lock
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/datetimetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -2916,6 +2916,9 @@ def test_strptime(self):
with self.assertRaises(ValueError): strptime("-000", "%z")
with self.assertRaises(ValueError): strptime("z", "%z")

# test only ascii is allowed
with self.assertRaises(ValueError): strptime('٢025-03-09', '%Y-%m-%d')

def test_strptime_single_digit(self):
# bpo-34903: Check that single digit dates and times are allowed.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:func:`datetime.datetime.strptime` now only accepts ASCII input.
Loading