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

Function detach_callable

mypy/checker.py:9128–9138  ·  view source on GitHub ↗

Ensures that the callable's type variables are 'detached' and independent of the context. A callable normally keeps track of the type variables it uses within its 'variables' field. However, if the callable is from a method and that method is using a class type variable, the callable wi

(typ: CallableType, class_type_vars: list[TypeVarLikeType])

Source from the content-addressed store, hash-verified

9126
9127
9128def detach_callable(typ: CallableType, class_type_vars: list[TypeVarLikeType]) -> CallableType:
9129 """Ensures that the callable's type variables are 'detached' and independent of the context.
9130
9131 A callable normally keeps track of the type variables it uses within its 'variables' field.
9132 However, if the callable is from a method and that method is using a class type variable,
9133 the callable will not keep track of that type variable since it belongs to the class.
9134 """
9135 if not class_type_vars:
9136 # Fast path, nothing to update.
9137 return typ
9138 return typ.copy_modified(variables=list(typ.variables) + class_type_vars)
9139
9140
9141def overload_can_never_match(signature: CallableType, other: CallableType) -> bool:

Calls 2

listClass · 0.85
copy_modifiedMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…