{"record":{"id":"cd2f03861e7025ca","repo":"pypa/pip","slug":"e","errorCode":null,"errorMessage":"{e}","messagePattern":"\\{e\\}","errorType":"exception","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/pkg_resources/__init__.py","lineNumber":1630,"sourceCode":"        e.filename = None\n        e.lineno = None\n        return e\n    return False\n\n\ndef evaluate_marker(text: str, extra: str | None = None) -> bool:\n    \"\"\"\n    Evaluate a PEP 508 environment marker.\n    Return a boolean indicating the marker result in this environment.\n    Raise SyntaxError if marker is invalid.\n\n    This implementation uses the 'pyparsing' module.\n    \"\"\"\n    try:\n        marker = _packaging_markers.Marker(text)\n        return marker.evaluate()\n    except _packaging_markers.InvalidMarker as e:\n        raise SyntaxError(e) from e\n\n\nclass NullProvider:\n    \"\"\"Try to implement resources and metadata for arbitrary PEP 302 loaders\"\"\"\n\n    egg_name: str | None = None\n    egg_info: str | None = None\n    loader: _LoaderProtocol | None = None\n\n    def __init__(self, module: _ModuleLike):\n        self.loader = getattr(module, '__loader__', None)\n        self.module_path = os.path.dirname(getattr(module, '__file__', ''))\n\n    def get_resource_filename(self, manager: ResourceManager, resource_name: str):\n        return self._fn(self.module_path, resource_name)\n\n    def get_resource_stream(self, manager: ResourceManager, resource_name: str):\n        return io.BytesIO(self.get_resource_string(manager, resource_name))","sourceCodeStart":1612,"sourceCodeEnd":1648,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/pkg_resources/__init__.py#L1612-L1648","documentation":"Raised as SyntaxError by evaluate_marker() when the PEP 508 environment marker string is invalid. The function wraps a packaging Marker and, on packaging.markers.InvalidMarker, re-raises it as SyntaxError with the original message preserved (via from e). This normalizes marker-validation errors into the SyntaxError family for callers.","triggerScenarios":"Calling evaluate_marker('python_version >') or any malformed PEP 508 marker string with invalid syntax, unknown variables, or unbalanced operators.","commonSituations":"Dynamically building marker strings from user input or config; a marker with a typo or unsupported variable name; markers copied from a malformed setup.cfg/pyproject.toml.","solutions":["Validate/repair the marker string syntax before calling evaluate_marker(); use packaging.markers.Marker() directly for clearer errors.","Catch SyntaxError around evaluate_marker() and report the invalid marker to the user.","Avoid constructing marker strings by string concatenation; use a known-good template."],"exampleFix":"// before\nresult = evaluate_marker('python_version >>= 3.8')  # invalid operator\n// after\nresult = evaluate_marker('python_version >= \"3.8\"')","handlingStrategy":"try-catch","validationCode":"# Validate marker syntax first\nfrom packaging.markers import Marker, InvalidMarker\ntry:\n    Marker(marker_text)\nexcept InvalidMarker:\n    marker_text = None","typeGuard":"from packaging.markers import Marker, InvalidMarker\ndef is_valid_marker(text: str) -> bool:\n    try:\n        Marker(text)\n        return True\n    except InvalidMarker:\n        return False","tryCatchPattern":"try:\n    evaluate_marker(text)\nexcept SyntaxError as e:\n    print(f'Invalid PEP 508 marker: {e}')","preventionTips":["Never build marker strings by string concatenation from untrusted input.","Validate markers with packaging.markers.Marker() first."],"tags":["pkg-resources","markers","pep508","syntax"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}