Title: datetime: pure Python implementation of `fromisoformat()` handles times with trailing spaces inconsistently with the C extension · Issue #130959 · python/cpython · GitHub
Open Graph Title: datetime: pure Python implementation of `fromisoformat()` handles times with trailing spaces inconsistently with the C extension · Issue #130959 · python/cpython
X Title: datetime: pure Python implementation of `fromisoformat()` handles times with trailing spaces inconsistently with the C extension · Issue #130959 · python/cpython
Description: Bug report Bug description: Discovered primarily because PyPy uses the Python version of datetime from the stdlib, and django.utils.dateparse.parse_datetime() supports wider range of values than the C version of datetime.datetime.fromiso...
Open Graph Description: Bug report Bug description: Discovered primarily because PyPy uses the Python version of datetime from the stdlib, and django.utils.dateparse.parse_datetime() supports wider range of values than th...
X Description: Bug report Bug description: Discovered primarily because PyPy uses the Python version of datetime from the stdlib, and django.utils.dateparse.parse_datetime() supports wider range of values than th...
Opengraph URL: https://github.com/python/cpython/issues/130959
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"datetime: pure Python implementation of `fromisoformat()` handles times with trailing spaces inconsistently with the C extension","articleBody":"# Bug report\n\n### Bug description:\n\nDiscovered primarily because PyPy uses the Python version of `datetime` from the stdlib, and `django.utils.dateparse.parse_datetime()` supports wider range of values than the C version of `datetime.datetime.fromisoformat()`, and falls back to their own parser.\n\n```python\n>>> datetime.datetime.fromisoformat(\"2012-04-23T10:20:30.400\")\ndatetime.datetime(2012, 4, 23, 10, 20, 30, 400000)\n>>> datetime.datetime.fromisoformat(\"2012-04-23T10:20:30.400 \")\ndatetime.datetime(2012, 4, 23, 10, 20, 30, 40000)\n>>> datetime.datetime.fromisoformat(\"2012-04-23T10:20:30.400 \")\ndatetime.datetime(2012, 4, 23, 10, 20, 30, 4000)\n>>> datetime.datetime.fromisoformat(\"2012-04-23T10:20:30.400 \")\ndatetime.datetime(2012, 4, 23, 10, 20, 30, 400)\n>>> datetime.datetime.fromisoformat(\"2012-04-23T10:20:30.400 \")\nTraceback (most recent call last):\n File \"\u003cpython-input-9>\", line 1, in \u003cmodule>\n datetime.datetime.fromisoformat(\"2012-04-23T10:20:30.400 \")\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/home/mgorny/git/cpython/Lib/_pydatetime.py\", line 1949, in fromisoformat\n raise ValueError(\n f'Invalid isoformat string: {date_string!r}') from None\nValueError: Invalid isoformat string: '2012-04-23T10:20:30.400 '\n>>> datetime.datetime.fromisoformat(\"2012-04-23T10:20:30.400 +02:30\")\ndatetime.datetime(2012, 4, 23, 10, 20, 30, 40000, tzinfo=datetime.timezone(datetime.timedelta(seconds=9000)))\n```\n\nFor comparison, the C extension rejects all variants containing spaces, causing Django to use its own parser.\n\nPyPy bug report: https://github.com/pypy/pypy/issues/5240\n\nI'm going to try preparing a patch.\n\n### CPython versions tested on:\n\n3.11, 3.13, CPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-130962\n* gh-131076\n* gh-131086\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/mgorny","@type":"Person","name":"mgorny"},"datePublished":"2025-03-07T17:31:01Z","url":"https://github.com/python/cpython/issues/130959"}
| react-profiling | 0 |
| react-import-map | react,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-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:5026b8e5-04ce-2c1c-74f3-a7641e98587b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B904:928E2:35F76BD:47EA962:6B0209C8 |
| html-safe-nonce | 6dfe7f6d5b02e0fced32b4d7eec2b07055237a8cf411ca08eec8a971e9e8b5e1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOTA0OjkyOEUyOjM1Rjc2QkQ6NDdFQTk2Mjo2QjAyMDlDOCIsInZpc2l0b3JfaWQiOiI2OTM1ODQ2NjY4Nzk0NjE4MzIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 38266ff5a641469895c48490d3d44c5fdbdeaccad153d62a85bf95c8239f5f42 |
| hovercard-subject-tag | issue:2903564063 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/130959/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8e392d93b442efdbb3604018d4bbd26ca421125dc25c0ed3a68ab8f70b3e8fd1/python/cpython/issues/130959 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8e392d93b442efdbb3604018d4bbd26ca421125dc25c0ed3a68ab8f70b3e8fd1/python/cpython/issues/130959 |
| og:image:alt | Bug report Bug description: Discovered primarily because PyPy uses the Python version of datetime from the stdlib, and django.utils.dateparse.parse_datetime() supports wider range of values than th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mgorny |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width