in chz/factories.py [0:0]
def _return_prospective(obj: Any, annotation: TypeForm, factory: str) -> Any:
if annotation not in {
object,
typing.Any,
typing_extensions.Any,
}:
if is_subtype_instance(obj, annotation):
# Allow things to be instances!
return lambda: obj
elif not callable(obj):
# ...including if we would just error on the next line
return lambda: obj
if not callable(obj):
raise MetaFromString(f"Expected {obj} from {factory!r} to be callable")
if isinstance(obj, type) and not is_subtype(obj, annotation):
extra = ""
if getattr(annotation, "__module__", None) == "__main__":
if any(
hasattr(sys.modules["__main__"], (witness := parent).__name__)
for parent in obj.__mro__
):
extra = f" (there may be confusion between {type_repr(witness)} and __main__:{witness.__name__})"
raise MetaFromString(
f"Expected {type_repr(obj)} from {factory!r} to be a subtype of {type_repr(annotation)}{extra}"
)
return obj