in chz/factories.py [0:0]
def get_unspecified_from_annotation(annotation: TypeForm) -> Callable[..., Any] | None:
if typing.get_origin(annotation) is type:
base_type = typing.get_args(annotation)[0]
if not isinstance(getattr(base_type, "__origin__", base_type), type):
# No unspecified for type[SpecialForm] e.g. type[int | str]
# TODO: annotated
return None
return type[base_type] # type: ignore[return-value]
if is_union_type(annotation):
type_args = typing.get_args(annotation)
if type_args and len(type_args) == 2 and type(None) in type_args:
unwrapped_optional = [t for t in type_args if t is not type(None)][0]
if callable(unwrapped_optional):
return unwrapped_optional
return None
if is_instantiable_type(annotation):
return annotation # type: ignore[return-value]
if annotation is None:
return lambda: None
# Probably a special form
return None