{"record":{"id":"81e002a4b500b8e8","repo":"pypa/pip","slug":"unexpected-trailing-data-s","errorCode":null,"errorMessage":"unexpected trailing data: %s","messagePattern":"unexpected trailing data: (.+?)","errorType":"exception","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/distlib/util.py","lineNumber":259,"sourceCode":"                else:\n                    m = VERSION_IDENTIFIER.match(s)\n                    if not m:\n                        raise SyntaxError('invalid constraint: %s' % s)\n                    v = m.groups()[0]\n                    s = s[m.end():].lstrip()\n                    if s:\n                        raise SyntaxError('invalid constraint: %s' % s)\n                    versions = [('~=', v)]\n\n    if remaining:\n        if remaining[0] != ';':\n            raise SyntaxError('invalid requirement: %s' % remaining)\n        remaining = remaining[1:].lstrip()\n\n        mark_expr, remaining = parse_marker(remaining)\n\n    if remaining and remaining[0] != '#':\n        raise SyntaxError('unexpected trailing data: %s' % remaining)\n\n    if not versions:\n        rs = distname\n    else:\n        rs = '%s %s' % (distname, ', '.join(['%s %s' % con for con in versions]))\n    return Container(name=distname, extras=extras, constraints=versions, marker=mark_expr, url=uri, requirement=rs)\n\n\ndef get_resources_dests(resources_root, rules):\n    \"\"\"Find destinations for resources files\"\"\"\n\n    def get_rel_path(root, path):\n        # normalizes and returns a lstripped-/-separated path\n        root = root.replace(os.path.sep, '/')\n        path = path.replace(os.path.sep, '/')\n        assert path.startswith(root)\n        return path[len(root):].lstrip('/')\n","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/distlib/util.py#L241-L277","documentation":"Raised as SyntaxError inside parse_requirement when, after successfully parsing the name, version, extras, URL, and any environment marker, there is still leftover data that does not start with '#' (a comment). The PEP 508 grammar allows an optional trailing comment but nothing else; any other residue is rejected as malformed. This guards against requirement strings with duplicate or appended junk after a complete, valid spec.","triggerScenarios":"parse_requirement('pkg>=1.0; python_version<\"3\" garbage'), parse_requirement('pkg==1.0 ;; marker'), or any string where a second ';' or extra token survives marker parsing. Also triggered by trailing characters after a valid marker expression that are not a '#' comment.","commonSituations":"Reading requirement lines from a file where multiple requirements got concatenated; requirements with double semicolons or stray punctuation after the marker; pasting specs that include inline annotations outside a comment.","solutions":["Strip or split the line so only one requirement remains; trailing comments must start with '#'.","Run a pre-pass that normalizes whitespace and removes anything after the first '#' before parsing.","Use packaging's Requirement parser to localize where the surplus data begins."],"exampleFix":"// before\nparse_requirement('pkg==1.0 ; python_version<\"3\" ; extra')\n// after\nparse_requirement('pkg==1.0 ; python_version<\"3\"  # note')","handlingStrategy":"validation","validationCode":"def strip_requirement_line(line):\n    line = line.split('#', 1)[0].strip()  # drop comment + surrounding ws\n    return line","typeGuard":"null","tryCatchPattern":"try:\n    parse_requirement(line)\nexcept SyntaxError as e:\n    if 'unexpected trailing data' in str(e):\n        line = line.split(';', 1)[0].strip()\n        parse_requirement(line)","preventionTips":["Split requirement lines on '#' before parsing.","Ensure one requirement per line when reading from files."],"tags":["parsing","requirements","pep508","distlib","syntax-error"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}