Skip to content

Hypothesis ≥ 6.130.13 on Python 3.9 doesn't support the LL(1) parser anymore #4421

@the-13th-letter

Description

@the-13th-letter

CPython 3.9 can optionally still use the older LL(1) parser (Python 3.8 and lower), instead of the newer LL(1) parser (Python 3.10 and higher). The LL(1) parser does not understand the full set of syntax legalized with Python 3.9… in particular, it cannot parse with (expr1 as expr2, expr3 as expr4) statements correctly.

As of hypothesis-python-6.130.13, the code no longer parses under the LL(1) parser. For example, using pytest and coverage in a Python 3.9 hatch environment with PYTHONOLDPARSER=1 set yields the following syntax error [non-public bits have been redacted]:

ImportError while loading conftest '.../tests/conftest.py'.
tests/__init__.py:26: in <module>
    import hypothesis
.../.local/share/hatch/env/virtual/.../lib/python3.9/site-packages/hypothesis/__init__.py:29: in <module>
    from hypothesis.core import example, find, given, reproduce_failure, seed
.../.local/share/hatch/pythons/3.9/python/lib/python3.9/ast.py:50: in parse
    return compile(source, filename, mode, flags,
E     File ".../.local/share/hatch/env/virtual/.../lib/python3.9/site-packages/hypothesis/core.py", line 1108
E       BuildContext(data, is_final=is_final) as context,
E                                             ^
E   SyntaxError: invalid syntax
.../.local/share/hatch/env/virtual/.../lib/python3.9/site-packages/coverage/inorout.py:509: CoverageWarning: Module ... was never imported. (module-not-imported)
  self.warn(f"Module {pkg} was never imported.", slug="module-not-imported")

(The same happens in a PyPy 3.9 environment with PYTHONOLDPARSER=1.)


The issue is due to f151eec (6.130.13), which specifically refactored this snippet of code into the Py3.9/LL(1)-incompatible form, starting from the compatible form. I suggest reverting this snippet to the LL(1)-compatible form.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions