Repository navigation
Fixes #814 - #818
Open
tony1233200 wants to merge 1 commit into
Open
Fixes #814#818tony1233200 wants to merge 1 commit into
tony1233200 wants to merge 1 commit into
Conversation
This branch has not been deployed
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 change
parse_timedelta("1h30m")used to return exactly one hour: the trailing\w*in_PARSE_TD_REwas meant to swallow the rest of a spelled-outunit word (
hours,minutes, …), but\walso matches digits, so on"1h30m"it consumed"30m"as though it were part of the unit nameh, leaving nothing forfinditerto find as a second match. Everyunit after the first in a compact string was silently discarded.
This PR replaces
\w*with[a-zA-Z]*inboltons/timeutils.py, soonly letters can follow the unit's first letter and the next numeric
value starts a new match. Spelled-out units (
"1 hour 30 minutes")and space-separated forms (
"1h 30m") behave exactly as before.Adds
test_parse_timedelta_compact_multi_unitcovering the sixpreviously wrong inputs from the issue (
"1h30m","1h30m15s","2d4h","1m30s","1w2d","3d12h") plus the spelled-out andspace-separated controls.
The backstory
I ran into this while parsing compact duration strings (timeouts and
TTLs) out of config files:
"1h30m"came back as one hour with noerror, so a cache TTL expired 30 minutes early and nothing in the log
explained why. The issue's table matched what I was seeing exactly,
so I traced it to the regex and fixed it at the source rather than
working around it at the call site.
AI assistance
parse_timedeltasilently drops every unit after the first in compact strings like "1h30m" #814:parse_timedelta("1h30m")silently parses only the first unit. Read the full issue first, clone with --depth 1, pass the quality gate — minimal repro (fails without the fix, passes with it), full related tests plus lint, follow the repo's CONTRIBUTING/AGENTS.md — and deliver a patch file, PR body, and repro script."Verification
repro_814.py, 14 cases + garbage check): 6/15 failedbefore the fix (
"1h30m"->1:00:00,"2d4h"->2 days, 0:00:00,…), 0/15 failed after.
(verified by stashing the one-line change and re-running).
pytest --doctest-modules boltons/timeutils.py tests/test_timeutils.py: 25 passedpytest --doctest-modules boltons tests: 776 passed, 22 subtests passedpyproject.toml, tox.ini, or CI workflows);
py_compileclean on bothchanged files. CI runs pytest via tox.