MCPcopy Index your code
hub / github.com/python/mypy / function_type

Function function_type

mypy/typeops.py:865–889  ·  view source on GitHub ↗
(func: FuncBase, fallback: Instance)

Source from the content-addressed store, hash-verified

863
864
865def function_type(func: FuncBase, fallback: Instance) -> FunctionLike:
866 if func.type:
867 assert isinstance(func.type, FunctionLike)
868 return func.type
869 else:
870 # Implicit type signature with dynamic types.
871 if isinstance(func, FuncItem):
872 return callable_type(func, fallback)
873 else:
874 # Either a broken overload, or decorated overload type is not ready.
875 # TODO: make sure the caller defers if possible.
876 assert isinstance(func, OverloadedFuncDef)
877 any_type = AnyType(TypeOfAny.from_error)
878 dummy = CallableType(
879 [any_type, any_type],
880 [ARG_STAR, ARG_STAR2],
881 [None, None],
882 any_type,
883 fallback,
884 line=func.line,
885 is_ellipsis_args=True,
886 )
887 # Return an Overloaded, because some callers may expect that
888 # an OverloadedFuncDef has an Overloaded type.
889 return Overloaded([dummy])
890
891
892def callable_type(

Calls 5

AnyTypeClass · 0.90
CallableTypeClass · 0.90
OverloadedClass · 0.90
isinstanceFunction · 0.85
callable_typeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…