Skip to content

Conversation

@milssky
Copy link

I have made things!

@pradeep90 hey! Your code is broken :) Can you validate it?

In hypothesis==6.137.2, this code produced the following output:

>>>fromhypothesisimportstrategiesasst>>>st.functions( ... like=lambda*args, **kwargs: None, ... returns=st.booleans(), ... pure=True, ... ) functions(like=lambda*args, **kwargs: <unknown>, returns=booleans(), pure=True)

Whereas in hypothesis==6.140.2, the output is already:

functions(like=lambda *args, **kwargs: None, returns=booleans(), pure=True) 

So this is indeed a direct change in the library itself.

Checklist

  • I have double checked that there are no unrelated changes in this pull request (old patches, accidental config files, etc)
  • I have created at least one test case for the changes I have made
  • I have updated the documentation for the changes I have made
  • I have added my changes to the CHANGELOG.md

Related issues

Refs #2262

🙏 Please, if you or your company finds dry-python valuable, help us sustain the project by sponsoring it transparently on https://github.com/sponsors/dry-python. As a thank you, your profile/company logo will be added to our main README which receives hundreds of unique visitors per day.

@codecov
Copy link

codecovbot commented Sep 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (82ef3ef) to head (c2edebb).
⚠️ Report is 410 commits behind head on master.

Additional details and impacted files
@@ Coverage Diff @@## master #2263 +/- ## ========================================== Coverage 100.00% 100.00% ========================================== Files 80 81 +1 Lines 2485 2581 +96 Branches 437 44 -393 ========================================== + Hits 2485 2581 +96 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

assert (
_strategy_string(result[callable_type], Callable[[int, str], bool])
=='functions(like=lambda *args, **kwargs: <unknown>,'
=='functions(like=lambda *args, **kwargs: None,'
Copy link
Member

@sobolevnsobolevnSep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question is: does this function actually return None? Or is it a repr bug?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weirder and weirder

>>>fromhypothesis.internal.lambda_sourcesimportlambda_description>>>lambda_description(lambda*args, **kwargs: None) 'lambda *args, **kwargs: None'>>>lambda_description(lambda*args: None) 'lambda *args: <unknown>'>>>lambda_description(lambda: None) 'lambda: <unknown>'

I keep looking

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the repr of lambdas was changed in HypothesisWorks/hypothesis#4500. Afaics, they used to always use <unknown>, but now they refine the lambda body string where possible. I think this should be a harmless change for us.

(Found this via the changelog for 6.137.3

https://github.com/HypothesisWorks/hypothesis/blob/275d4964d1df8f3bcac5eef96c36407d15824b56/hypothesis-python/docs/changelog.rst?plain=1#L233-L245

This patch makes the stringification of lambdas, and as a result certain automatic filter rewriting operations, more robust. This fixes issue https://github.com/HypothesisWorks/hypothesis/issues/4498, where a lambda was mistakenly identified as the identity operator due to "inspect.getsource()" only returning the first line of the lambda definition. As a result, the "repr" of strategies filtered or mapped by lambda functions may change slightly. 

)

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@milssky@pradeep90@sobolevn