-
Notifications
You must be signed in to change notification settings - Fork 587
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
Check for settings assigned as attribute on StateMachine class #1643
Comments
This issue would be a good introduction to Hypothesis for an intermediate programmer who understands metaclasses, or at least can follow the example of |
Hey Zac, I would like to give this a shot! Before I start, I have a question: There is a 2.7/3.x compatibility issue with the way metaclasses are assigned to classes. There are solutions to this in |
I would simply copy the implementation of hypothesis/hypothesis-python/src/hypothesis/_settings.py Lines 99 to 135 in dd46aca
As far as I'm aware this is compatible with both Python2 and Python3, though I could be wrong! |
Thanks for clarifying, Zac. I misunderstood how |
#1638 allows
@settings(...)
to be used as a class decorator on state machine classes, which substantially improves the ergonomics. However, the old mechanism of assigning an attribute is still supported. #1642 points out a fairly subtle trap in this behavior though, by fixing it in the docs:Fortunately we can use essentially the same solution as in #1572, defining a custom
__setattr__
on a (new) metaclass ofGenericStateMachine
that will turn the incorrect usage from silent failure into an explicit error with a helpful message (which can also suggest the decorator form).This should error when the
.settings
attribute on the class is assigned an instance ofsettings
, but allow other types to be assigned to minimize false-positives. We should not restrict attributes on instances if we can avoid it.The text was updated successfully, but these errors were encountered: