Skip to content

Commit ab0db81

Browse files
committed
Split Specifier regex into operator and version parts
Tokenizer uses _version_regex_str to detect 'VERSION' token.
1 parent 885248c commit ab0db81

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packaging/specifiers.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,10 @@ def wrapped(self: "Specifier", prospective: ParsedVersion, spec: str) -> bool:
316316

317317
class Specifier(_IndividualSpecifier):
318318

319-
_regex_str = r"""
319+
_operator_regex_str = r"""
320320
(?P<operator>(~=|==|!=|<=|>=|<|>|===))
321+
"""
322+
_version_regex_str = r"""
321323
(?P<version>
322324
(?:
323325
# The identity operators allow for an escape hatch that will
@@ -409,7 +411,10 @@ class Specifier(_IndividualSpecifier):
409411
)
410412
"""
411413

412-
_regex = re.compile(r"^\s*" + _regex_str + r"\s*$", re.VERBOSE | re.IGNORECASE)
414+
_regex = re.compile(
415+
r"^\s*" + _operator_regex_str + _version_regex_str + r"\s*$",
416+
re.VERBOSE | re.IGNORECASE,
417+
)
413418

414419
_operators = {
415420
"~=": "compatible",

0 commit comments

Comments
 (0)