From 3a98accc4e93b154e06021474b0a9ef379cb2723 Mon Sep 17 00:00:00 2001 From: Zac Hatfield-Dodds Date: Sun, 11 Feb 2024 11:44:01 -0800 Subject: [PATCH] Work around weird Black issue --- hypothesis-python/src/hypothesis/extra/_patching.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/hypothesis-python/src/hypothesis/extra/_patching.py b/hypothesis-python/src/hypothesis/extra/_patching.py index 2660e04a90..e0c360cc5a 100644 --- a/hypothesis-python/src/hypothesis/extra/_patching.py +++ b/hypothesis-python/src/hypothesis/extra/_patching.py @@ -86,7 +86,7 @@ def __init__(self, context, fn_examples, strip_via=(), dec="example", width=88): # Codemod the failing examples to Call nodes usable as decorators self.fn_examples = { - k: tuple(self.__call_node_to_example_dec(ex, via) for ex, via in nodes) + k: tuple((d := self.__call_node_to_example_dec(*x)) for x in nodes if d) for k, nodes in fn_examples.items() } @@ -116,10 +116,13 @@ def __call_node_to_example_dec(self, node, via): args=[cst.Arg(cst.SimpleString(repr(via)))], ) if black: # pragma: no branch - pretty = black.format_str( - cst.Module([]).code_for_node(via), - mode=black.FileMode(line_length=self.line_length), - ) + try: + pretty = black.format_str( + cst.Module([]).code_for_node(via), + mode=black.FileMode(line_length=self.line_length), + ) + except ImportError: # pragma: no cover + return None # See https://github.com/psf/black/pull/4224 via = cst.parse_expression(pretty.strip()) return cst.Decorator(via)