Skip to content

Commit

Permalink
Work around weird Black issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Feb 11, 2024
1 parent 288d3d0 commit 3a98acc
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions hypothesis-python/src/hypothesis/extra/_patching.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 3a98acc

Please # to comment.