Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support @example(...).via("string description") to track example provenance #3506

Closed
Zac-HD opened this issue Nov 12, 2022 · 2 comments
Closed
Labels
interop how to play nicely with other packages

Comments

@Zac-HD
Copy link
Member

Zac-HD commented Nov 12, 2022

Over in Zac-HD/hypofuzz#13, I mention using magic comments to track which @example() cases were automatically added by the fuzzer, to enably fully-automated maintanence of a static covering set.

It occured to me that provenance tracking might be a more generally desirable feature, and that a simple method which returns self might be a better way to implement this than comments. Once I hit on the short-and-sweet name via, I was sold. Probably requires some use of typing.Protocol to help type-checking tools understand that this is fine, with corresponding compatibility workaround on Python 3.7 (which predates Protocol). The resulting code might look like:

@example(0, 1)  # manually added
@example(1, 2).via("you can put anything you like in here")  # manually added
@example(3, 4).via("hypofuzz")  # added *and removable* by hypofuzz
@given(...)
def test(x: int, y: int):
    pass
@Zac-HD Zac-HD added the interop how to play nicely with other packages label Nov 12, 2022
@Zac-HD
Copy link
Member Author

Zac-HD commented Nov 27, 2022

Guess what? This is a syntax error before Python 3.9, because it requires PEP-614.

I find the idea of a # via: your string here comment aesthetically offensive, but since we'll be supporting 3.8 until the EOL in October 2025 I guess I'll have to suck it up and deal 😬. Or maybe we just tell people on older versions that they have to write

def fx(dec): return dec

@fx(example(...).via("your string here"))  # look, it's just a function call, no need for PEP-614 here...
def test(_):
    pass

(plus we'll need to update the base Python env if we want to show .via() in docs without breaking anything, etc...)

@Zac-HD
Copy link
Member Author

Zac-HD commented Dec 2, 2022

Closed by #3516.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interop how to play nicely with other packages
Projects
None yet
Development

No branches or pull requests

1 participant