{"record":{"id":"dddd37e1025b17a2","repo":"python/cpython","slug":"iso-year-directive-g-must-be-used-with-the-iso","errorCode":null,"errorMessage":"ISO year directive '%G' must be used with the ISO week directive '%V' and a weekday directive ('%A', '%a', '%w', or '%u').","messagePattern":"ISO year directive '%G' must be used with the ISO week directive '%V' and a weekday directive \\('%A', '%a', '%w', or '%u'\\)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Lib/_strptime.py","lineNumber":741,"sourceCode":"                    # Deal with bad locale setup where timezone names are the\n                    # same and yet time.daylight is true; too ambiguous to\n                    # be able to tell what timezone has daylight savings\n                    if (time.tzname[0] == time.tzname[1] and\n                       time.daylight and found_zone not in (\"utc\", \"gmt\")):\n                        break\n                    else:\n                        tz = value\n                        break\n\n    # Deal with the cases where ambiguities arise\n    # don't assume default values for ISO week/year\n    if iso_year is not None:\n        if julian is not None:\n            raise ValueError(\"Day of the year directive '%j' is not \"\n                             \"compatible with ISO year directive '%G'. \"\n                             \"Use '%Y' instead.\")\n        elif iso_week is None or weekday is None:\n            raise ValueError(\"ISO year directive '%G' must be used with \"\n                             \"the ISO week directive '%V' and a weekday \"\n                             \"directive ('%A', '%a', '%w', or '%u').\")\n    elif iso_week is not None:\n        if year is None or weekday is None:\n            raise ValueError(\"ISO week directive '%V' must be used with \"\n                             \"the ISO year directive '%G' and a weekday \"\n                             \"directive ('%A', '%a', '%w', or '%u').\")\n        else:\n            raise ValueError(\"ISO week directive '%V' is incompatible with \"\n                             \"the year directive '%Y'. Use the ISO year '%G' \"\n                             \"instead.\")\n\n    leap_year_fix = False\n    if year is None:\n        if month == 2 and day == 29:\n            year = 1904  # 1904 is first leap year of 20th century\n            leap_year_fix = True\n        else:","sourceCodeStart":723,"sourceCodeEnd":759,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Lib/_strptime.py#L723-L759","documentation":"The ISO year %G only makes sense together with the ISO week number %V and a weekday (%A, %a, %w, %u) — all three are needed to pin down a date. If %G matched but iso_week or weekday is None after processing, _strptime raises this ValueError.","triggerScenarios":"datetime.strptime('2020', '%G') or datetime.strptime('2020 W12', '%G %V') — %G present without a weekday, or without %V at all.","commonSituations":"Parsing partial ISO week-date strings such as '2020-W12' and forgetting the day component; truncated ISO strings copied from reports.","solutions":["Add the weekday to input and format: '2020 W12 3' with '%G W%V %u'","If the day is unknown, decide on a default (e.g. Monday) and append it before parsing"],"exampleFix":"# before\n>>> datetime.strptime('2020 W12', '%G W%V')\nValueError: ISO year directive '%G' must be used with the ISO week directive '%V' and a weekday directive ('%A', '%a', '%w', or '%u').\n\n# after\n>>> datetime.strptime('2020 W12 1', '%G W%V %u')\ndatetime.datetime(2020, 3, 16, 0, 0)","handlingStrategy":"validation","validationCode":"def complete_iso_week_input(s: str, fmt: str):\n    if '%G' in fmt and '%V' not in fmt:\n        fmt += ' %V'\n        s += ' 01'\n    if not any(d in fmt for d in ('%A', '%a', '%w', '%u')):\n        fmt += ' %u'\n        s += ' 1'\n    return s, fmt","typeGuard":null,"tryCatchPattern":null,"preventionTips":["ISO week dates always need three parts: ISO year, week, weekday","Default missing weekdays explicitly (e.g. append Monday) before parsing","Write one canonical ISO-week parser helper instead of ad-hoc formats"],"tags":["strptime","iso-week","datetime","format-string","cpython"],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}