Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression when parsing pytz (>=2011k) after 21.3 to 22.0 upgrade #681

Closed
alexey-medvedchikov opened this issue Mar 3, 2023 · 5 comments

Comments

@alexey-medvedchikov
Copy link

Hi,

Thank you for all your hard work!

At some point we upgraded packaging from v21.3 to v22.0 and found a regression.

v21.3 works fine:

# pip3.7 install packaging==21.3
...
# echo "pytz (>=2011k)" | python3.7 -c "import packaging; from packaging.requirements import Requirement; print(vars(Requirement(input())))"
{'name': 'pytz', 'url': None, 'extras': set(), 'specifier': <SpecifierSet('>=2011k')>, 'marker': None}

v23.0 and v22.0 are broken (last version that works is v21.3):

# pip3.7 install packaging==23.0
...

# echo "pytz (>=2011k)" | python3.7 -c "import packaging; from packaging.requirements import Requirement; print(vars(Requirement(input())))"
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/packaging/requirements.py", line 35, in __init__
    parsed = parse_requirement(requirement_string)
  File "/usr/local/lib/python3.7/site-packages/packaging/_parser.py", line 64, in parse_requirement
    return _parse_requirement(Tokenizer(source, rules=DEFAULT_RULES))
  File "/usr/local/lib/python3.7/site-packages/packaging/_parser.py", line 82, in _parse_requirement
    url, specifier, marker = _parse_requirement_details(tokenizer)
  File "/usr/local/lib/python3.7/site-packages/packaging/_parser.py", line 120, in _parse_requirement_details
    specifier = _parse_specifier(tokenizer)
  File "/usr/local/lib/python3.7/site-packages/packaging/_parser.py", line 209, in _parse_specifier
    tokenizer.consume("WS")
  File "/usr/local/lib/python3.7/contextlib.py", line 119, in __exit__
    next(self.gen)
  File "/usr/local/lib/python3.7/site-packages/packaging/_tokenizer.py", line 185, in enclosing_tokens
    span_start=open_position,
  File "/usr/local/lib/python3.7/site-packages/packaging/_tokenizer.py", line 166, in raise_syntax_error
    span=span,
packaging._tokenizer.ParserSyntaxError: Expected closing RIGHT_PARENTHESIS
    pytz (>=2011k)
         ~~~~~~~^

Test to reproduce the issue:

def test_specifier_ends_with_letter(self) -> None:
    # GIVEN
    to_parse = "name (>=2011k)"

    # WHEN
    req = Requirement(to_parse)

    # THEN
    assert req.name == "name"
    assert req.specifier == SpecifierSet('>=2011k')

Output from the test on current main:

self = <[AttributeError("'Requirement' object has no attribute 'name'") raised in repr()] Requirement object at 0x7fc3a1427040>
requirement_string = 'name (>=2011k)'

    def __init__(self, requirement_string: str) -> None:
        try:
            parsed = parse_requirement(requirement_string)
        except ParserSyntaxError as e:
>           raise InvalidRequirement(str(e)) from e
E           packaging.requirements.InvalidRequirement: Expected closing RIGHT_PARENTHESIS
E               name (>=2011k)
E                    ~~~~~~~^
@brettcannon
Copy link
Member

This is expected as 2100k is not a valid version number (see https://packaging.python.org/en/latest/specifications/version-specifiers/ for the spec). Starting in packaging 22 we stopped being permissive about this, hence the change in semantics (we raised a warning to try and let users know ahead of time that this change was coming).

@brettcannon brettcannon closed this as not planned Won't fix, can't repro, duplicate, stale Mar 3, 2023
@pradyunsg
Copy link
Member

See #530

@alexey-medvedchikov
Copy link
Author

Thanks @brettcannon for the info. This is sad. 😞

@cauldnz

This comment was marked as abuse.

@SouhaibUniv

This comment was marked as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants