Skip to content

Commit 3f545a6

Browse files
authored
Merge pull request #3548 from ThunderKey/feature/add-annotations-to-ghostwriter
Closes #3546
2 parents ae85e0e + 3f24137 commit 3f545a6

26 files changed

+469
-70
lines changed

AUTHORS.rst

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ their individual contributions.
121121
* `Munir Abdinur <https://github.com/mabdinur>`_
122122
* `Nicholas Chammas <https://github.com/nchammas>`_
123123
* `Nick Anyos <https://github.com/NickAnyos>`_
124+
* `Nicolas Ganz <https://github.com/ThunderKey>`_
124125
* `Nikita Sobolev <https://github.com/sobolevn>`_ ([email protected])
125126
* `Oleg Höfling <https://github.com/hoefling>`_ ([email protected])
126127
* `Paul Ganssle <https://ganssle.io>`_ ([email protected])

hypothesis-python/RELEASE.rst

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
RELEASE_TYPE: minor
2+
3+
The :doc:`Ghostwritter <ghostwriter>` will now include type annotations on tests
4+
for type-annotated code. If you want to force this to happen (or not happen),
5+
pass a boolean to the new ``annotate=`` argument to the Python functions, or
6+
the ``--[no-]annotate`` CLI flag.
7+
8+
Thanks to Nicolas Ganz for this new feature!

hypothesis-python/src/hypothesis/extra/cli.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,15 @@ def codemod(path):
269269
multiple=True,
270270
help="dotted name of exception(s) to ignore",
271271
)
272-
def write(func, writer, except_, style): # noqa: D301 # \b disables autowrap
272+
@click.option(
273+
"--annotate/--no-annotate",
274+
default=None,
275+
help="force ghostwritten tests to be type-annotated (or not). "
276+
"By default, match the code to test.",
277+
)
278+
def write(
279+
func, writer, except_, style, annotate
280+
): # noqa: D301 # \b disables autowrap
273281
"""`hypothesis write` writes property-based tests for you!
274282
275283
Type annotations are helpful but not required for our advanced introspection
@@ -278,6 +286,7 @@ def write(func, writer, except_, style): # noqa: D301 # \b disables autowrap
278286
\b
279287
hypothesis write gzip
280288
hypothesis write numpy.matmul
289+
hypothesis write pandas.from_dummies
281290
hypothesis write re.compile --except re.error
282291
hypothesis write --equivalent ast.literal_eval eval
283292
hypothesis write --roundtrip json.dumps json.loads
@@ -287,7 +296,7 @@ def write(func, writer, except_, style): # noqa: D301 # \b disables autowrap
287296
# NOTE: if you want to call this function from Python, look instead at the
288297
# ``hypothesis.extra.ghostwriter`` module. Click-decorated functions have
289298
# a different calling convention, and raise SystemExit instead of returning.
290-
kwargs = {"except_": except_ or (), "style": style}
299+
kwargs = {"except_": except_ or (), "style": style, "annotate": annotate}
291300
if writer is None:
292301
writer = "magic"
293302
elif writer == "idempotent" and len(func) > 1:

0 commit comments

Comments
 (0)