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

Function bind_self_fast

mypy/checkmember.py:1506–1528  ·  view source on GitHub ↗

Return a copy of `method`, with the type of its first parameter (usually self or cls) bound to original_type. This is a faster version of mypy.typeops.bind_self() that can be used for methods with trivial self/cls annotations.

(method: F, original_type: Type | None = None)

Source from the content-addressed store, hash-verified

1504
1505
1506def bind_self_fast(method: F, original_type: Type | None = None) -> F:
1507 """Return a copy of `method`, with the type of its first parameter (usually
1508 self or cls) bound to original_type.
1509
1510 This is a faster version of mypy.typeops.bind_self() that can be used for methods
1511 with trivial self/cls annotations.
1512 """
1513 if isinstance(method, Overloaded):
1514 items = [bind_self_fast(c, original_type) for c in method.items]
1515 return cast(F, Overloaded(items))
1516 assert isinstance(method, CallableType)
1517 if not method.arg_types:
1518 # Invalid method, return something.
1519 return method
1520 if method.arg_kinds[0] in (ARG_STAR, ARG_STAR2):
1521 # See typeops.py for details.
1522 return method
1523 return method.copy_modified(
1524 arg_types=method.arg_types[1:],
1525 arg_kinds=method.arg_kinds[1:],
1526 arg_names=method.arg_names[1:],
1527 is_bound=True,
1528 )
1529
1530
1531def has_operator(typ: Type, op_method: str) -> bool:

Calls 3

OverloadedClass · 0.90
isinstanceFunction · 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…