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

Warn when an @st.composite strategy doesn't use the draw() function #3384

Closed
Zac-HD opened this issue Jun 26, 2022 · 10 comments · Fixed by #3412
Closed

Warn when an @st.composite strategy doesn't use the draw() function #3384

Zac-HD opened this issue Jun 26, 2022 · 10 comments · Fixed by #3412
Labels
legibility make errors helpful and Hypothesis grokable

Comments

@Zac-HD
Copy link
Member

Zac-HD commented Jun 26, 2022

I've seen a few cases where users have missed the point of @st.composite, and ended up using it as a substitute for st.just():

@st.composite
def foo(_):
    return "bar"

I propose to fix this by using inspect.getsource()+ast.parse()+a custom AST visitor, which will raise an explanatory error (initially a deprecation warning) if the draw argument is not referenced in the function body. Note that the name of said argument is determined by the AST of the function signature, and the ctx of the node must be Load().

@Zac-HD Zac-HD added the legibility make errors helpful and Hypothesis grokable label Jun 26, 2022
@Zac-HD Zac-HD mentioned this issue Jul 14, 2022
20 tasks
@rodrigogiraoserrao
Copy link
Contributor

rodrigogiraoserrao commented Jul 16, 2022

Me, @gzaxel, and @bomtall are going to be tackling this. Wish us luck 😜

gzaxel pushed a commit to bomtall/hypothesis that referenced this issue Jul 16, 2022
bomtall added a commit to bomtall/hypothesis that referenced this issue Jul 16, 2022
…lled within function when using composite decorator
bomtall added a commit to bomtall/hypothesis that referenced this issue Jul 16, 2022
…lled within function when using composite decorator
bomtall added a commit to bomtall/hypothesis that referenced this issue Jul 16, 2022
…lled within function when using composite decorator
bomtall added a commit to bomtall/hypothesis that referenced this issue Jul 16, 2022
…lled within function when using composite decorator
gzaxel pushed a commit to bomtall/hypothesis that referenced this issue Jul 17, 2022
gzaxel added a commit to bomtall/hypothesis that referenced this issue Jul 17, 2022
@Jookia
Copy link

Jookia commented Jul 18, 2022

Is there a way to turn this off? I have code that wraps test code that may draw data but may not.

@bomtall
Copy link
Contributor

bomtall commented Jul 18, 2022 via email

@Jookia
Copy link

Jookia commented Jul 18, 2022 via email

@Zac-HD
Copy link
Member Author

Zac-HD commented Jul 18, 2022

@Jookia can you post the function in question? This new check is quite precise, so if you have a warning it's probably a real problem.

@Jookia
Copy link

Jookia commented Jul 18, 2022 via email

@Zac-HD
Copy link
Member Author

Zac-HD commented Jul 18, 2022

Again, your description is too vague for me to follow, if you can't post the actual source code I'm just going to move on.

@Jookia
Copy link

Jookia commented Jul 18, 2022

It's no big deal, I solved it with a pin.

@rodrigogiraoserrao
Copy link
Contributor

rodrigogiraoserrao commented Jul 18, 2022 via email

@Jookia
Copy link

Jookia commented Jul 18, 2022

Look, this change has rubbed me the wrong way: It doesn't deprecate a feature or code, instead goes out of the way to break code by walking the AST and effectively doing linting that I didn't ask for. Nowhere in the documentation has it even been suggested that you need to draw things in all code that uses st.composite and I'm effectively being punished for writing code 'wrong' despite following all the rules and best practices I've had access to. I have no idea what's going to be restricted next, so pinning solves this for my immediate future before more of my code is crippled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legibility make errors helpful and Hypothesis grokable
Projects
None yet
4 participants