Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
chore: use fullmatch in a couple more places
Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
  • Loading branch information
henryiii committed Nov 27, 2025
commit b6bdd17a08da23545a6fb8ade13ead4b898ec6ac
8 changes: 4 additions & 4 deletions src/packaging/specifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class Specifier(BaseSpecifier):
"""

_regex = re.compile(
r"^\s*" + _operator_regex_str + _version_regex_str + r"\s*$",
r"\s*" + _operator_regex_str + _version_regex_str + r"\s*",
re.VERBOSE | re.IGNORECASE,
)

Expand Down Expand Up @@ -254,7 +254,7 @@ def __init__(self, spec: str = "", prereleases: bool | None = None) -> None:
:raises InvalidSpecifier:
If the given specifier is invalid (i.e. bad syntax).
"""
match = self._regex.search(spec)
match = self._regex.fullmatch(spec)
if not match:
raise InvalidSpecifier(f"Invalid specifier: {spec!r}")

Expand Down Expand Up @@ -649,7 +649,7 @@ def filter(
yield from prereleases_versions


_prefix_regex = re.compile(r"^([0-9]+)((?:a|b|c|rc)[0-9]+)$")
_prefix_regex = re.compile(r"([0-9]+)((?:a|b|c|rc)[0-9]+)")


def _version_split(version: str) -> list[str]:
Expand All @@ -666,7 +666,7 @@ def _version_split(version: str) -> list[str]:
result.append(epoch or "0")

for item in rest.split("."):
match = _prefix_regex.search(item)
match = _prefix_regex.fullmatch(item)
if match:
result.extend(match.groups())
else:
Expand Down
Loading