"""This module provides a single type: :py:class:`SequenceNotStr`. This type is equivalentto :py:class:`typing.Sequence` except it excludes values of type :py:class:`str` and:py:class:`bytes` from the set of valid instances. This can be useful when you want toeliminate the easy mistake of forgetting to wrap a string value in a containingsequence."""from__future__importannotationsfromcollections.abcimportSequencefromtypingimportGenericfromtypingimportTypeVarfromtyping_extensionsimportget_argsfrom.importPhantomfrom.import_hypothesisfrom.predicatesimportbooleanfrom.predicates.genericimportof_type__all__=("SequenceNotStr",)T=TypeVar("T")
[docs]classSequenceNotStr(Sequence[T],Phantom,Generic[T],# Note: We don't eliminate mutable types here like in PhantomSized. This is because# the property of not being a str cannot change by mutation, so this specific# phantom type is safe to use with mutable types.predicate=boolean.negate(of_type((str,bytes))),):@classmethoddef__register_strategy__(cls)->_hypothesis.HypothesisStrategy:fromhypothesis.strategiesimportfrom_typefromhypothesis.strategiesimporttuplesdefcreate_strategy(type_:type[T],)->_hypothesis.SearchStrategy[tuple[T,...]]|None:(inner_type,)=get_args(type_)returntuples(from_type(inner_type))returncreate_strategy