def _create_hyp_nested_strategy(simple_class_strategy):
"""
Create a recursive attrs class.
Given a strategy for building (simpler) classes, create and return
a strategy for building classes that have as an attribute:
* just the simpler class
* a list of simpler classes
* a dict mapping the string "cls" to a simpler class.
"""
# A strategy producing tuples of the form ([list of attributes], <given
# class strategy>).
attrs_and_classes = st.tuples(lists_of_attrs(defaults=True),
simple_class_strategy)
return (attrs_and_classes.flatmap(just_class) |
attrs_and_classes.flatmap(list_of_class) |
attrs_and_classes.flatmap(dict_of_class))
评论列表
文章目录