{"record":{"id":"4b4ced204a131d72","repo":"pypa/pip","slug":"invalid-specification-s","errorCode":null,"errorMessage":"Invalid specification '%s'","messagePattern":"Invalid specification '(.+?)'","errorType":"exception","errorClass":"DistlibException","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/distlib/util.py","lineNumber":729,"sourceCode":"                      and self.flags == other.flags)\n        return result\n\n    __hash__ = object.__hash__\n\n\nENTRY_RE = re.compile(\n    r'''(?P<name>([^\\[]\\S*))\n                      \\s*=\\s*(?P<callable>(\\w+)([:\\.]\\w+)*)\n                      \\s*(\\[\\s*(?P<flags>[\\w-]+(=\\w+)?(,\\s*\\w+(=\\w+)?)*)\\s*\\])?\n                      ''', re.VERBOSE)\n\n\ndef get_export_entry(specification):\n    m = ENTRY_RE.search(specification)\n    if not m:\n        result = None\n        if '[' in specification or ']' in specification:\n            raise DistlibException(\"Invalid specification \"\n                                   \"'%s'\" % specification)\n    else:\n        d = m.groupdict()\n        name = d['name']\n        path = d['callable']\n        colons = path.count(':')\n        if colons == 0:\n            prefix, suffix = path, None\n        else:\n            if colons != 1:\n                raise DistlibException(\"Invalid specification \"\n                                       \"'%s'\" % specification)\n            prefix, suffix = path.split(':')\n        flags = d['flags']\n        if flags is None:\n            if '[' in specification or ']' in specification:\n                raise DistlibException(\"Invalid specification \"\n                                       \"'%s'\" % specification)","sourceCodeStart":711,"sourceCodeEnd":747,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/distlib/util.py#L711-L747","documentation":"Raised as DistlibException by distlib.util.get_export_entry when the specification string fails to match ENTRY_RE (the 'name = module:attr [flags]' export grammar) AND contains an unbalanced or stray '[' or ']'. Because the regex requires well-formed optional flags, a leftover bracket signals a malformed flags section rather than a simply-unknown format. The function returns None (no error) when the spec is unparseable but contains no brackets.","triggerScenarios":"get_export_entry('cli = mod:main [bad flag spec'), get_export_entry('name = mod:attr extra['), or any entry-point spec where '[' or ']' appears but the whole string doesn't match the ENTRY_RE grammar (e.g. unbalanced brackets, spaces breaking the regex).","commonSituations":"Hand-editing entry_points strings in setup.py/setup.cfg; metadata export lists generated by a tool that malformed the flags field; legacy entry point syntax with stray brackets.","solutions":["Ensure the spec matches 'name = module.path:attribute [flag=value,...]' with balanced brackets.","Remove stray '[' / ']' characters that are not part of a flags block.","Validate entry-point strings with packaging.entry_points or importlib.metadata before passing to get_export_entry."],"exampleFix":"# before\nget_export_entry('run = mod:main [console_scripts')\n# after\nget_export_entry('run = mod:main [console_scripts]')","handlingStrategy":"validation","validationCode":"from distlib.util import ENTRY_RE\n\ndef valid_export_spec(spec):\n    return bool(ENTRY_RE.search(spec)) and spec.count('[') == spec.count(']')","typeGuard":"def is_balanced_brackets(s: str) -> bool:\n    return isinstance(s, str) and s.count('[') == s.count(']')","tryCatchPattern":"from distlib.util import DistlibException\ntry:\n    get_export_entry(spec)\nexcept DistlibException as e:\n    if 'Invalid specification' in str(e):\n        fix_brackets(spec)","preventionTips":["Validate entry-point strings with importlib.metadata.","Keep flags block as a single trailing '[...]'."],"tags":["parsing","entry-points","distlib","metadata","specification"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}