Skip to content

Commit b6bdd17

Browse files
committed
chore: use fullmatch in a couple more places
Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
1 parent cf45527 commit b6bdd17

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/packaging/specifiers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class Specifier(BaseSpecifier):
226226
"""
227227

228228
_regex = re.compile(
229-
r"^\s*" + _operator_regex_str + _version_regex_str + r"\s*$",
229+
r"\s*" + _operator_regex_str + _version_regex_str + r"\s*",
230230
re.VERBOSE | re.IGNORECASE,
231231
)
232232

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

@@ -649,7 +649,7 @@ def filter(
649649
yield from prereleases_versions
650650

651651

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

654654

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

668668
for item in rest.split("."):
669-
match = _prefix_regex.search(item)
669+
match = _prefix_regex.fullmatch(item)
670670
if match:
671671
result.extend(match.groups())
672672
else:

0 commit comments

Comments
 (0)