{"record":{"id":"782dc5af31126c20","repo":"RustPython/RustPython","slug":"invalid-isoformat-string-date-string-r","errorCode":null,"errorMessage":"Invalid isoformat string: {date_string!r}","messagePattern":"Invalid isoformat string: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Lib/_pydatetime.py","lineNumber":1050,"sourceCode":"\n        January 1 of year 1 is day 1.  Only the year, month and day are\n        non-zero in the result.\n        \"\"\"\n        y, m, d = _ord2ymd(n)\n        return cls(y, m, d)\n\n    @classmethod\n    def fromisoformat(cls, date_string):\n        \"\"\"Construct a date from a string in ISO 8601 format.\"\"\"\n\n        if not isinstance(date_string, str):\n            raise TypeError('Argument must be a str')\n\n        if not date_string.isascii():\n            raise ValueError('Argument must be an ASCII str')\n\n        if len(date_string) not in (7, 8, 10):\n            raise ValueError(f'Invalid isoformat string: {date_string!r}')\n\n        try:\n            return cls(*_parse_isoformat_date(date_string))\n        except Exception:\n            raise ValueError(f'Invalid isoformat string: {date_string!r}')\n\n    @classmethod\n    def fromisocalendar(cls, year, week, day):\n        \"\"\"Construct a date from the ISO year, week number and weekday.\n\n        This is the inverse of the date.isocalendar() function\"\"\"\n        return cls(*_isoweek_to_gregorian(year, week, day))\n\n    @classmethod\n    def strptime(cls, date_string, format):\n        \"\"\"Parse a date string according to the given format (like time.strptime()).\"\"\"\n        import _strptime\n        return _strptime._strptime_datetime_date(cls, date_string, format)","sourceCodeStart":1032,"sourceCodeEnd":1068,"githubUrl":"https://github.com/RustPython/RustPython/blob/aaeab4f754b4f40efc0c8ab39cf7c4a3c35a8cfd/Lib/_pydatetime.py#L1032-L1068","documentation":"date.fromisoformat only accepts date-only ISO strings whose length is exactly 7 (YYYY-DDD ordinal), 8 (YYYYMMDD), or 10 (YYYY-MM-DD); any other length raises ValueError('Invalid isoformat string: ...'). Full timestamps, week dates with extra fields, and strings carrying offsets belong to datetime.fromisoformat, not date.fromisoformat.","triggerScenarios":"date.fromisoformat('2020-01-01T00:00:00') (19 chars); '2020-01-01T00:00' (16); truncated '2020-0' or '2020-01-0'; strings with 'Z' or '+02:00' appended (13+ chars).","commonSituations":"Feeding API timestamp strings into date.fromisoformat instead of datetime.fromisoformat; assuming 'YYYY-MM' or 'YYYY-Www' alone is supported; keeping UTC offsets attached when only the date is wanted.","solutions":["For full timestamps use datetime.datetime.fromisoformat(s).date()","When the format is fixed, slice the date part: date.fromisoformat(s[:10])","Pre-validate len(s) in (7, 8, 10) and emit your own descriptive error"],"exampleFix":"// before\nd = date.fromisoformat(iso_ts)   # iso_ts == '2020-01-01T12:00:00+02:00'\n\n// after\nimport datetime as dt\nd = dt.datetime.fromisoformat(iso_ts).date()","handlingStrategy":"validation","validationCode":"if len(s) not in (7, 8, 10):\n    raise ValueError(f'{s!r} is not a date-only ISO string (YYYY-DDD, YYYYMMDD, or YYYY-MM-DD); use datetime.fromisoformat for timestamps')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use datetime.datetime.fromisoformat(s).date() for full timestamps","Slice fixed-format inputs (s[:10]) before calling date.fromisoformat","Remember only lengths 7, 8, 10 are date-forms; everything else is a datetime job"],"tags":["datetime","isoformat","iso8601","valueerror","input-length"],"backgroundTag":"iso8601-parse-failed","analyzedSha":"aaeab4f754b4f40efc0c8ab39cf7c4a3c35a8cfd","analyzedAt":"2026-08-17T00:37:52.100Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}