-
Notifications
You must be signed in to change notification settings - Fork 586
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
st.builds() works incorrectly with annotated __init__
#2603
Comments
|
Ok, this happens because of this line: https://github.com/HypothesisWorks/hypothesis/blob/hypothesis-python-5.31.0/hypothesis-python/src/hypothesis/internal/compat.py#L157-L158 Introduced in At this point Related #2388 I am not sure how to fix this 🤔 |
|
Actually, no. It was working the same way even before try:
hints = typing.get_type_hints(thing)
except (TypeError, NameError):
hints = {}
if hints or not inspect.isclass(thing):
return hints
try:
return typing.get_type_hints(thing.__init__)
except (TypeError, NameError, AttributeError):
return {}Here, Proposed solution:
So, I can rewrite some parts of |
|
An alternative would be to try each method of getting hints in order of preference ( Happy to review whatever approach you think will work though :-) |
The simplest reproduction is:
Outputs:
Why does this happen?
My debugging session shows that:
requiredhere is equal to{'inner_value'}__init__method. It results in{'_inner_value': ~_ValueType}I can fix it! The only question I have is:
Is it ok to chage how we get annotation from
targetif we are dealing with__init__?The text was updated successfully, but these errors were encountered: