MCPcopy
hub / github.com/python/mypy / callable_type

Function callable_type

mypy/typeops.py:892–916  ·  view source on GitHub ↗
(
    fdef: FuncItem, fallback: Instance, ret_type: Type | None = None
)

Source from the content-addressed store, hash-verified

890
891
892def callable_type(
893 fdef: FuncItem, fallback: Instance, ret_type: Type | None = None
894) -> CallableType:
895 # TODO: somewhat unfortunate duplication with prepare_method_signature in semanal
896 if fdef.info and fdef.has_self_or_cls_argument and fdef.arg_names:
897 self_type: Type = fill_typevars(fdef.info)
898 if fdef.is_class or fdef.name == "__new__":
899 self_type = TypeType.make_normalized(self_type)
900 args = [self_type] + [AnyType(TypeOfAny.unannotated)] * (len(fdef.arg_names) - 1)
901 else:
902 args = [AnyType(TypeOfAny.unannotated)] * len(fdef.arg_names)
903
904 return CallableType(
905 args,
906 fdef.arg_kinds,
907 fdef.arg_names,
908 ret_type or AnyType(TypeOfAny.unannotated),
909 fallback,
910 name=fdef.name,
911 line=fdef.line,
912 column=fdef.column,
913 implicit=True,
914 # We need this for better error messages, like missing `self` note:
915 definition=fdef if isinstance(fdef, FuncDef) else None,
916 )
917
918
919def try_getting_str_literals(expr: Expression, typ: Type) -> list[str] | None:

Callers 2

visit_lambda_exprMethod · 0.90
function_typeFunction · 0.85

Calls 6

fill_typevarsFunction · 0.90
AnyTypeClass · 0.90
CallableTypeClass · 0.90
lenFunction · 0.85
isinstanceFunction · 0.85
make_normalizedMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…