From b997a48f2a5cdefb11c834b00eeb17a2d15c37c5 Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Wed, 7 Dec 2022 01:10:40 +0000 Subject: [PATCH] Permit arbitrary whitespace around versions specifier in parenthesis This is more consistent with the rest of the format which is largely whitespace agnostic. --- packaging/_parser.py | 6 ++++-- tests/test_requirements.py | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packaging/_parser.py b/packaging/_parser.py index d03119a1..4dcf03d1 100644 --- a/packaging/_parser.py +++ b/packaging/_parser.py @@ -197,11 +197,13 @@ def _parse_extras_list(tokenizer: Tokenizer) -> List[str]: def _parse_specifier(tokenizer: Tokenizer) -> str: """ - specifier = LEFT_PARENTHESIS version_many RIGHT_PARENTHESIS - | version_many + specifier = LEFT_PARENTHESIS WS? version_many WS? RIGHT_PARENTHESIS + | WS? version_many WS? """ with tokenizer.enclosing_tokens("LEFT_PARENTHESIS", "RIGHT_PARENTHESIS"): + tokenizer.consume("WS") parsed_specifiers = _parse_version_many(tokenizer) + tokenizer.consume("WS") return parsed_specifiers diff --git a/tests/test_requirements.py b/tests/test_requirements.py index 92cf9ce6..36ea474b 100644 --- a/tests/test_requirements.py +++ b/tests/test_requirements.py @@ -79,9 +79,9 @@ ("git+https://git.example.com/MyProject.git@v1.0", ""), ("git+https://git.example.com/MyProject.git@refs/pull/123/head", ""), (None, "==={ws}arbitrarystring"), - (None, "(==={ws}arbitrarystring)"), + (None, "({ws}==={ws}arbitrarystring{ws})"), (None, "=={ws}1.0"), - (None, "(=={ws}1.0)"), + (None, "({ws}=={ws}1.0{ws})"), (None, "<={ws}1!3.0.0.rc2"), (None, ">{ws}2.2{ws},{ws}<{ws}3"), (None, "(>{ws}2.2{ws},{ws}<{ws}3)"),