You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm expecting a protocol without any methods to be able to passed in to from_type, but that doesn't work.
Additionally, a bare class with only class variables can also not be passed to from_type, but a dataclass can.
Your NoMethods protocol is not actually runtime-checkable (because it has non-method attributes), so Hypothesis can't handle this at runtime. Unfortunate, but nothing we can do there.
from_type() successfully generates instances of the bare class - the fact that this doesn't actually ensure that the x attribute exists is not Hypothesis' problem.
@dataclass generates an __init__() method which takes a float x and assigns it to an attribute, so this works.
An internal _from_protocol() strategy to use for non-runtime-checkable protocols would be technically feasible, but providing objects with no useful behavior which technically satisfy the protocol just doesn't seem very useful to me.
I'm expecting a protocol without any methods to be able to passed in to
from_type
, but that doesn't work.Additionally, a bare class with only class variables can also not be passed to
from_type
, but a dataclass can.Fails with message:
FAILED test.py::test_can_handle_methodless_protocols - TypeError: Protocols with non-method members don't support issubclass()
The bare class example:
Fails with message:
FAILED test.py::test_can_handle_methodless_protocols - AttributeError: 'NoMethods' object has no attribute 'x'
The dataclass example:
does pass. I would expect all of them to
On the other hand, a protocol is a non-runtime thing, so maybe there should be a separate strategy
from_protocol
?The text was updated successfully, but these errors were encountered: