Better handling of covariance, contravariance, and TypeVar in from_type()
#2094
Labels
enhancement
it's not broken, but we want it to be better
hypothesis/hypothesis-python/src/hypothesis/searchstrategy/types.py
Lines 118 to 126 in 2c6b6f3
Type variables are tricky!
shared()strategy should be keyed onf"typevar-{thing.__name__}"shared()! Otherwise it's not really a typevar...shared()of)from_type(getattr(thing, "__bound__", object))to generalise thetext()hack.A larger problem is that
from_type()currently always treats things as covariant (i.e. returns a strategy for subtypes if the exact type is unknown). We should probably provide an argument for in/co/contra variance and default to invariance, which will be an annoying deprecation pathway. Plus use that from the TypeVar handling, obviously.(this should be retagged from
enhancementtobugif it's seen in the wild)The text was updated successfully, but these errors were encountered: