René's URL Explorer Experiment


Title: datetime/time.fromisoformat: C accelerator accepts an empty fraction before a timezone designator · Issue #152157 · python/cpython · GitHub

Open Graph Title: datetime/time.fromisoformat: C accelerator accepts an empty fraction before a timezone designator · Issue #152157 · python/cpython

X Title: datetime/time.fromisoformat: C accelerator accepts an empty fraction before a timezone designator · Issue #152157 · python/cpython

Description: Bug report The C accelerator for datetime.fromisoformat() and time.fromisoformat() accepts a decimal separator (. or ,) that is followed by zero fractional digits when a timezone designator (+, -, or Z) comes next. The pure-Python implem...

Open Graph Description: Bug report The C accelerator for datetime.fromisoformat() and time.fromisoformat() accepts a decimal separator (. or ,) that is followed by zero fractional digits when a timezone designator (+, -, ...

X Description: Bug report The C accelerator for datetime.fromisoformat() and time.fromisoformat() accepts a decimal separator (. or ,) that is followed by zero fractional digits when a timezone designator (+, -, ...

Opengraph URL: https://github.com/python/cpython/issues/152157

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"datetime/time.fromisoformat: C accelerator accepts an empty fraction before a timezone designator","articleBody":"## Bug report\n\nThe C accelerator for `datetime.fromisoformat()` and `time.fromisoformat()` accepts a\ndecimal separator (`.` or `,`) that is followed by **zero** fractional digits when a\ntimezone designator (`+`, `-`, or `Z`) comes next. The pure-Python implementation\n(`_pydatetime`) correctly rejects these strings with\n`ValueError: Invalid isoformat string`.\n\n## Reproduction\n\n```python\n>>> import datetime\n>>> datetime.datetime.fromisoformat('2020-01-01T12:34:56.+05:00')\ndatetime.datetime(2020, 1, 1, 12, 34, 56, tzinfo=datetime.timezone(datetime.timedelta(seconds=18000)))\n>>> datetime.time.fromisoformat('12:34:56.Z')\ndatetime.time(12, 34, 56, tzinfo=datetime.timezone.utc)\n```\n\nThe C implementation parses these and silently sets `microsecond=0`. The pure-Python\nimplementation raises:\n\n```python\n>>> import _pydatetime\n>>> _pydatetime.datetime.fromisoformat('2020-01-01T12:34:56.+05:00')\nTraceback (most recent call last):\n  ...\nValueError: Invalid isoformat string: '2020-01-01T12:34:56.+05:00'\n```\n\n## C-vs-pure-Python divergence\n\n| Input                          | C accelerator         | Pure-Python (`_pydatetime`) |\n|--------------------------------|-----------------------|-----------------------------|\n| `'2020-01-01T12:34:56.+05:00'` | parses, microsecond=0 | `ValueError`                |\n| `'2020-01-01T12:34:56.Z'`      | parses, microsecond=0 | `ValueError`                |\n| `'2020-01-01T12:34:56,+05:00'` | parses, microsecond=0 | `ValueError`                |\n| `'12:34:56.+05:00'`            | parses, microsecond=0 | `ValueError`                |\n| `'12:34:56,+05:00'`            | parses, microsecond=0 | `ValueError`                |\n| `'12:34:56.Z'`                 | parses, microsecond=0 | `ValueError`                |\n\nControl cases that already agree (both reject / both accept), unchanged:\n\n| Input             | C / pure-Python                 |\n|-------------------|---------------------------------|\n| `'12:34:56.'`     | both `ValueError`               |\n| `'12:34:56.5'`    | both `time(12, 34, 56, 500000)` |\n| `'12:34:56+05:00'`| both accept (no fraction)       |\n\n## Which side is wrong\n\nThe C accelerator is the lenient (wrong) side; pure-Python is correct.\n\n- ISO 8601 §4.2.2.4 and RFC 3339 §5.6: a decimal sign in a time fraction must be\n  followed by at least one fractional digit. An empty fraction is not valid.\n- The C implementation already rejects the standalone trailing decimal separator\n  (`'12:34:56.'`), so rejecting `'12:34:56.+05:00'` is consistent with its own\n  end-of-string behavior; the lenient outcome here is incidental rather than intentional.\n\n## Root cause\n\nIn `Modules/_datetimemodule.c`, `parse_hh_mm_ss_ff()` consumes the `.`/`,` separator and\nthen computes `to_parse` as the number of fractional-digit characters. When a timezone\ndesignator follows immediately, the time substring handed to the function ends right after\nthe separator, so the generic end-of-substring check\n(`if (p >= p_end) return c != '\\0';`) fires *before* the decimal-separator branch and\nreturns \"trailing content present\" (1) rather than flagging an empty fraction. The caller\nthen accepts the value because a timezone is present. The standalone-`.` case is rejected\nonly because that same end-of-string check happens to map to a `ValueError` in the\nno-timezone path.\n\n## Suggested fix\n\nReject `parse_hh_mm_ss_ff()` when a `.`/`,` separator is seen but no fractional digit\nfollows, by handling the decimal-separator case before the generic end-of-substring check.\nThis matches the pure-Python behavior and the spec. A patch and regression tests are ready.\n\nAlternative the maintainers may prefer: make pure-Python lenient instead. The spec\n(≥1 digit required) and the C implementation's own rejection of the standalone trailing\nseparator both argue for fixing C to reject, so that is what the attached patch does.\n\n## Environment\n\nReproduced on current `main` (3.16.0a0). Affects all maintained branches that ship the C\naccelerator.\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-152161\n* gh-152761\n* gh-152765\n* gh-152766\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/tonghuaroot","@type":"Person","name":"tonghuaroot"},"datePublished":"2026-06-25T07:03:57Z","url":"https://github.com/python/cpython/issues/152157"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:02bd75af-e3f1-252d-6209-841dd7f61a60
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8EE2:3E418A:15AE24D:1C856C4:6B01FA89
html-safe-nonce998d09cd1b5bee8dc76c84c38da258df6a531ddd1c7e8471cc1c97323191042b
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RUUyOjNFNDE4QToxNUFFMjREOjFDODU2QzQ6NkIwMUZBODkiLCJ2aXNpdG9yX2lkIjoiNDE3MDY1MDE4NjY3MjExMDIxNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac6eb4ccd1048c4519465cab2016cf5a3558310f2b2e72a90edf7677e9386d1aac
hovercard-subject-tagissue:4741520544
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/152157/issue_layout
twitter:imagehttps://opengraph.githubassets.com/75055f575418e81893576f0873a41a1d552eea138abc6092d021fbbfba6b4714/python/cpython/issues/152157
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/75055f575418e81893576f0873a41a1d552eea138abc6092d021fbbfba6b4714/python/cpython/issues/152157
og:image:altBug report The C accelerator for datetime.fromisoformat() and time.fromisoformat() accepts a decimal separator (. or ,) that is followed by zero fractional digits when a timezone designator (+, -, ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernametonghuaroot
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/152157#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F152157
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F152157
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/152157
Reloadhttps://github.com/python/cpython/issues/152157
Reloadhttps://github.com/python/cpython/issues/152157
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/152157
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/152157
#152161https://github.com/python/cpython/pull/152161
datetime/time.fromisoformat: C accelerator accepts an empty fraction before a timezone designatorhttps://github.com/python/cpython/issues/152157#top
#152161https://github.com/python/cpython/pull/152161
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/tonghuaroot
tonghuaroothttps://github.com/tonghuaroot
on Jun 25, 2026https://github.com/python/cpython/issues/152157#issue-4741520544
gh-152157: Reject empty fraction before timezone in C fromisoformat #152161https://github.com/python/cpython/pull/152161
[3.15] gh-152157: Reject empty fractions in _datetime.{date}time.fromisoformat (GH-152161) #152761https://github.com/python/cpython/pull/152761
[3.14] gh-152157: Reject empty fractions in _datetime.{date}time.fromisoformat (GH-152161) #152765https://github.com/python/cpython/pull/152765
[3.13] gh-152157: Reject empty fractions in _datetime.{date}time.fromisoformat (GH-152161) #152766https://github.com/python/cpython/pull/152766
StanFromIrelandhttps://github.com/StanFromIreland
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
on Jun 25, 2026https://github.com/python/cpython/issues/152157#event-27186456158
StanFromIrelandhttps://github.com/StanFromIreland
Date and time issues 🕰️https://github.com/orgs/python/projects/21
on Jun 25, 2026https://github.com/python/cpython/issues/152157#event-27186463363
StanFromIrelandhttps://github.com/StanFromIreland
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#152161https://github.com/python/cpython/pull/152161
on Jul 1, 2026https://github.com/python/cpython/issues/152157#event-27421793824
StanFromIrelandhttps://github.com/StanFromIreland
on Jul 1, 2026https://github.com/python/cpython/issues/152157#event-27421793826
gh-152157: Reject empty fractions in `_datetime.{date}time.fromisofor…https://github.com/python/cpython/commit/112c69a0514902af2d2f7d0503de6690ca59a10f
gh-152157https://github.com/python/cpython/issues/152157
112c69ahttps://github.com/python/cpython/commit/112c69a0514902af2d2f7d0503de6690ca59a10f
github-project-automationhttps://github.com/apps/github-project-automation
Date and time issues 🕰️https://github.com/orgs/python/projects/21
on Jul 1, 2026https://github.com/python/cpython/issues/152157
StanFromIrelandhttps://github.com/StanFromIreland
on Jul 1, 2026https://github.com/python/cpython/issues/152157#event-27422982699
[3.15] gh-152157: Reject empty fractions in `_datetime.{date}time.fro…https://github.com/python/cpython/commit/63da6c86eb7e10b04ce39d3dff70e77a1ace4255
gh-152157https://github.com/python/cpython/issues/152157
63da6c8https://github.com/python/cpython/commit/63da6c86eb7e10b04ce39d3dff70e77a1ace4255
StanFromIrelandhttps://github.com/StanFromIreland
on Jul 8, 2026https://github.com/python/cpython/issues/152157#event-27710426987
[3.14] gh-152157: Reject empty fractions in `_datetime.{date}time.fro…https://github.com/python/cpython/commit/0a29ea5bf60f1bff8b316c735038bc1dc16e4c18
gh-152157https://github.com/python/cpython/issues/152157
0a29ea5https://github.com/python/cpython/commit/0a29ea5bf60f1bff8b316c735038bc1dc16e4c18
[3.13] gh-152157: Reject empty fractions in `_datetime.{date}time.fro…https://github.com/python/cpython/commit/670b4ac596999d207480350cf4c01e3f49a92eab
gh-152157https://github.com/python/cpython/issues/152157
670b4achttps://github.com/python/cpython/commit/670b4ac596999d207480350cf4c01e3f49a92eab
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/152157
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/152157
extension-modulesC modules in the Modules dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22extension-modules%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
Date and time issues 🕰️https://github.com/orgs/python/projects/21
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.