Repository navigation
Do not raise ValueError for digits that int() does not know - #1581
Merged
AdrianAtZyte merged 3 commits intoNov 13, 2026
Merged
Conversation
The timestamp parser finds its digits with a regular expression of the regex module, whose \d knows digits that were added to Unicode after the Unicode version of this Python, and converts them with int(), which rejects them. Such digits made parse() and search_dates() raise ValueError, e.g. when DEFAULT_LANGUAGES is set or IGNORE_SURROUNDING_TEXT is enabled, instead of the text not being a timestamp.
The part-of-day step finds the hour before words such as "night" with a regular expression of the regex module, whose \d knows digits that were added to Unicode after the Unicode version of this Python, and converts it with int(), which rejects them. Such a digit before a part of the day made parse() and search_dates() raise ValueError, e.g. in "5 UTC-1200 <digit> night". Treat it like a number that is not an hour.
The Russian compound ordinals ("двадцать первое") are combined with int(),
after the numbers of two neighbouring tokens were found with \d of the regex
module, which knows digits that were added to Unicode after the Unicode
version of this Python and which int() rejects. "20 <digit>" made parse() and
search_dates() raise ValueError, with default settings. Leave such a pair as
it is, as for any other number that is not combined.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1581 +/- ##
=======================================
Coverage 99.23% 99.24%
=======================================
Files 239 239
Lines 4203 4212 +9
=======================================
+ Hits 4171 4180 +9
Misses 32 32 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
AdrianAtZyte
approved these changes
Nov 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The regex module can read as digits characters that were added to Unicode after the Unicode version of the running Python, and
int()rejects them. Three places convert such a digit withint()without checking it, soparse()andsearch_dates()raisedValueErrorfor a text that holds one:DEFAULT_LANGUAGESset or withIGNORE_SURROUNDING_TEXTenabled (date.py);5 UTC-1200 <digit> night(_parts_of_day.py);20 <digit>(locale.py).One commit per place. Each treats the text as not matching, like any other text that is not a timestamp, an hour or a compound ordinal. The existing checks are kept: only a text that raised
ValueErroris affected.Results of texts that worked before do not change: 3,600 calls of
parse()andsearch_dates()on timestamps, parts of the day and Russian number pairs written with the digits of eight scripts (ASCII, Arabic-Indic, Persian, Devanagari, Bengali, Thai, fullwidth, Mongolian) and with digits thatint()rejects give the same result on master and on this branch, except that the 378 calls that raisedValueErrorno longer do.Each commit has a test that makes
int()fail by patching it, so it runs on every Python and regex version, and tests with real digits that the regex module knows andint()rejects (digits_unknown_to_int()intests/__init__.py, found at run time; skipped when there are none). The later commits reuse the helper of the first.🤖 Generated with Claude Code