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)
| 1504 | |
| 1505 | |
| 1506 | def 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 | |
| 1531 | def has_operator(typ: Type, op_method: str) -> bool: |
no test coverage detected
searching dependent graphs…