diff --git a/AUTHORS.rst b/AUTHORS.rst index 189ac64e75..4946f2fa00 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -120,6 +120,7 @@ their individual contributions. * `Louis Taylor `_ * `Luke Barone-Adesi `_ * `Lundy Bernard `_ +* `Marco Ricci `_ * `Marco Sirabella `_ * `marekventur `_ * `Marius Gedminas `_ (marius@gedmin.as) diff --git a/hypothesis-python/RELEASE.rst b/hypothesis-python/RELEASE.rst new file mode 100644 index 0000000000..4f8c42c91a --- /dev/null +++ b/hypothesis-python/RELEASE.rst @@ -0,0 +1,7 @@ +RELEASE_TYPE: patch + +This patch restores compatibility when using `the legacy Python 3.9 LL(1) +parser `__, which +was accidentally broken since :ref:`version 6.130.13 `. + +Thanks to Marco Ricci for this fix! diff --git a/hypothesis-python/src/hypothesis/core.py b/hypothesis-python/src/hypothesis/core.py index 33c52d13e9..93cdda08ca 100644 --- a/hypothesis-python/src/hypothesis/core.py +++ b/hypothesis-python/src/hypothesis/core.py @@ -1102,18 +1102,19 @@ def run(data: ConjectureData) -> None: # self.test_runner can include the execute_example method, or setup/teardown # _example, so it's important to get the PRNG and build context in place first. - with ( - local_settings(self.settings), - deterministic_PRNG(), - BuildContext(data, is_final=is_final) as context, - ): - # providers may throw in per_case_context_fn, and we'd like - # `result` to still be set in these cases. - result = None - with data.provider.per_test_case_context_manager(): - # Run the test function once, via the executor hook. - # In most cases this will delegate straight to `run(data)`. - result = self.test_runner(data, run) + # + # NOTE: For compatibility with Python 3.9's LL(1) parser, this is written as + # three nested with-statements, instead of one compound statement. + with local_settings(self.settings): + with deterministic_PRNG(): + with BuildContext(data, is_final=is_final) as context: + # providers may throw in per_case_context_fn, and we'd like + # `result` to still be set in these cases. + result = None + with data.provider.per_test_case_context_manager(): + # Run the test function once, via the executor hook. + # In most cases this will delegate straight to `run(data)`. + result = self.test_runner(data, run) # If a failure was expected, it should have been raised already, so # instead raise an appropriate diagnostic error.