From 6dd499cf3e862d33d6aacc9867244643acf99f06 Mon Sep 17 00:00:00 2001 From: Jakub Kuczys Date: Wed, 14 Sep 2022 03:01:47 +0200 Subject: [PATCH 1/2] Raise InvalidRequirement from None --- packaging/requirements.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/requirements.py b/packaging/requirements.py index 971fb8fb..68f72bfd 100644 --- a/packaging/requirements.py +++ b/packaging/requirements.py @@ -39,7 +39,7 @@ def __init__(self, requirement_string: str) -> None: try: req = _RequirementTuple(*parse_named_requirement(requirement_string)) except ParseExceptionError as e: - raise InvalidRequirement(str(e)) + raise InvalidRequirement(str(e)) from None self.name: str = req.name if req.url: From 6d42ca3976ed469270daf3d9353cd27bd35af831 Mon Sep 17 00:00:00 2001 From: Jakub Kuczys Date: Wed, 28 Sep 2022 00:28:49 +0200 Subject: [PATCH 2/2] Use raise from exc syntax --- packaging/markers.py | 2 +- packaging/requirements.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/markers.py b/packaging/markers.py index ddb0ac17..384a0ff7 100644 --- a/packaging/markers.py +++ b/packaging/markers.py @@ -209,7 +209,7 @@ def __init__(self, marker: str) -> None: raise InvalidMarker( f"Invalid marker: {marker!r}, parse error at " f"{marker[e.position : e.position + 8]!r}" - ) + ) from e def __str__(self) -> str: return _format_marker(self._markers) diff --git a/packaging/requirements.py b/packaging/requirements.py index 68f72bfd..d469f973 100644 --- a/packaging/requirements.py +++ b/packaging/requirements.py @@ -39,7 +39,7 @@ def __init__(self, requirement_string: str) -> None: try: req = _RequirementTuple(*parse_named_requirement(requirement_string)) except ParseExceptionError as e: - raise InvalidRequirement(str(e)) from None + raise InvalidRequirement(str(e)) from e self.name: str = req.name if req.url: