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
Fix recursion issues #3687
Fix recursion issues #3687
Conversation
@@ -958,14 +959,13 @@ def builds( | |||
from hypothesis.strategies._internal.types import _global_type_lookup | |||
|
|||
for kw, t in infer_for.items(): | |||
if ( | |||
getattr(t, "__module__", None) in ("builtins", "typing") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example in #3026 (comment), actually didn't work now, because Optional[RecursiveClass].__module__
is typing
. (RecursiveClass|None).__module__
is types
, so that happened to work. And builtins
is probably also unnecessary because relevant builtins are registered in _global_type_lookup
anyway.
Long story short: Unless there's a reason I don't see, just remove the __module__
check and everything is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just FYI, this was the cause of the ghostwriter failures (now fixed).
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm looking forward to getting this in - see comments below, add release notes, and it looks like we'll need to do something about os.environ
in the ghostwriter too 🤔
I think I addressed everything (except ghostwriter), let's see how the tests turn out. Will revisit if not, but it may be a few days again |
Synced and rebased to fix conflict |
Let me know if you want me to dig in and offer some suggestions for or to push a fix for the ghostwriter issue; by default I'm happy to leave it to your judgement. |
I committed a change to ghostwriter to just undo the earlier (new) deferring. I'm not familiar enough with it to tell whether this is sufficiently precise or robust |
) | ||
|
||
|
||
def _from_type(thing: Type[Ex], recurse_guard: List[Type[Ex]]) -> SearchStrategy[Ex]: | ||
_recurse_guard: ContextVar = ContextVar("recurse_guard", default=[]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, this will actually share the same list across threads (contexts), won't it. I'll push a fix but it will add a bit of ugly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, the merge conflict is from this ongoing merge and should resolve itself momentarily.
Content looks great though, so I'll merge as soon as that previous release finishes!
Trying to finally kill that recursion zombie.
from_type
didn't properly detect recursion on types that went throughtypes.from_typing_type
. Fixed by moving the recurse-guard list to aContextVar
. (yep, I should have taken your advice on that in the first place @Zac-HD)Additionally:
whennicerepr
encounters an error (RecursionError for example), convert it to a warning and return a string anyway. This is what made it easy to identify the problem in the first place,Closes: #3525