{"record":{"id":"da912549363debc1","repo":"python/cpython","slug":"inconsistent-use-of-in-found-dict-group-key","errorCode":null,"errorMessage":"Inconsistent use of : in {found_dict[group_key]}","messagePattern":"Inconsistent use of : in (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Lib/_strptime.py","lineNumber":704,"sourceCode":"                # U starts week on Sunday.\n                week_of_year_start = 6\n            else:\n                # W starts week on Monday.\n                week_of_year_start = 0\n        elif group_key == 'V':\n            iso_week = int(found_dict['V'])\n        elif group_key in ('z', 'colon_z'):\n            z = found_dict[group_key]\n            if z:\n                if z == 'Z':\n                    gmtoff = 0\n                else:\n                    if z[3] == ':':\n                        z = z[:3] + z[4:]\n                        if len(z) > 5:\n                            if z[5] != ':':\n                                msg = f\"Inconsistent use of : in {found_dict[group_key]}\"\n                                raise ValueError(msg)\n                            z = z[:5] + z[6:]\n                    hours = int(z[1:3])\n                    minutes = int(z[3:5])\n                    seconds = int(z[5:7] or 0)\n                    gmtoff = (hours * 60 * 60) + (minutes * 60) + seconds\n                    gmtoff_remainder = z[8:]\n                    # Pad to always return microseconds.\n                    gmtoff_remainder_padding = \"0\" * (6 - len(gmtoff_remainder))\n                    gmtoff_fraction = int(gmtoff_remainder + gmtoff_remainder_padding)\n                    if z.startswith(\"-\"):\n                        gmtoff = -gmtoff\n                        gmtoff_fraction = -gmtoff_fraction\n        elif group_key == 'Z':\n            # Since -1 is default value only need to worry about setting tz if\n            # it can be something other than -1.\n            found_zone = found_dict['Z'].lower()\n            for value, tz_values in enumerate(locale_time.timezone):\n                if found_zone in tz_values:","sourceCodeStart":686,"sourceCodeEnd":722,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Lib/_strptime.py#L686-L722","documentation":"While post-processing a matched %z/%:z offset, _strptime normalizes colons out of the string; if the offset has a colon after the hours (z[3] == ':') it removes it, and then if seconds are present and the character at position 5 is not another ':', the format mixes colon and non-colon separators, raising this f-string ValueError showing the original matched group.","triggerScenarios":"An offset like '+05:0030' (colon between hours and minutes but not before seconds) parsed with %z/%:z — hours and minutes colon-separated while seconds are concatenated without one.","commonSituations":"Hand-built or corrupted timezone strings; concatenating offset parts with inconsistent separators; data from sources that emit '+HH:MMSS' malformed offsets.","solutions":["Normalize the offset string to either fully colon-separated '+HH:MM:SS' or fully compact '+HHMMSS' before parsing","Validate/repair offsets with a regex such as re.sub(r'(?<=\\d{2}):(?=\\d{2}(?!:))', '', s) to strip colons uniformly"],"exampleFix":"# before\n>>> datetime.strptime('+05:0030', '%z')\nValueError: Inconsistent use of : in +05:0030\n\n# after\n>>> datetime.strptime('+050030', '%z')\ndatetime.datetime(2025, 8, 14, 0, 0, 30, tzinfo=datetime.timezone(datetime.timedelta(hours=5, seconds=30)))","handlingStrategy":"validation","validationCode":"import re\n\ndef normalize_offset(s: str) -> str:\n    # make offset uniformly compact: +HH:MM:SS -> +HHMMSS\n    return re.sub(r'(?<=[+-]\\d{2}):(?=\\d{2}(?!:))', '', s)","typeGuard":null,"tryCatchPattern":"try:\n    dt = datetime.strptime(s, '%z')\nexcept ValueError as e:\n    if 'Inconsistent use of :' in str(e):\n        dt = datetime.strptime(normalize_offset(s), '%z')\n    else:\n        raise","preventionTips":["Generate offsets with one consistent separator style","Validate offsets with a strict regex before parsing","Use datetime.timezone(timedelta) to build offsets programmatically instead of string surgery"],"tags":["strptime","timezone","utc-offset","parsing","cpython"],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}