Type check a call that targets a callable value. See the docstring of check_call for more information.
(
self,
callee: CallableType,
args: list[Expression],
arg_kinds: list[ArgKind],
context: Context,
arg_names: Sequence[str | None] | None,
callable_node: Expression | None,
callable_name: str | None,
object_type: Type | None,
)
| 1649 | return self.msg.not_callable(callee, context), AnyType(TypeOfAny.from_error) |
| 1650 | |
| 1651 | def check_callable_call( |
| 1652 | self, |
| 1653 | callee: CallableType, |
| 1654 | args: list[Expression], |
| 1655 | arg_kinds: list[ArgKind], |
| 1656 | context: Context, |
| 1657 | arg_names: Sequence[str | None] | None, |
| 1658 | callable_node: Expression | None, |
| 1659 | callable_name: str | None, |
| 1660 | object_type: Type | None, |
| 1661 | ) -> tuple[Type, Type]: |
| 1662 | """Type check a call that targets a callable value. |
| 1663 | |
| 1664 | See the docstring of check_call for more information. |
| 1665 | """ |
| 1666 | # Always unpack **kwargs before checking a call. |
| 1667 | callee = callee.with_unpacked_kwargs().with_normalized_var_args() |
| 1668 | if callable_name is None and callee.name: |
| 1669 | callable_name = callee.name |
| 1670 | ret_type = get_proper_type(callee.ret_type) |
| 1671 | if callee.is_type_obj() and isinstance(ret_type, Instance): |
| 1672 | callable_name = ret_type.type.fullname |
| 1673 | if isinstance(callable_node, RefExpr) and callable_node.fullname in ENUM_BASES: |
| 1674 | # An Enum() call that failed SemanticAnalyzerPass2.check_enum_call(). |
| 1675 | return callee.ret_type, callee |
| 1676 | |
| 1677 | if ( |
| 1678 | callee.is_type_obj() |
| 1679 | and callee.type_object().is_protocol |
| 1680 | # Exception for Type[...] |
| 1681 | and not callee.from_type_type |
| 1682 | ): |
| 1683 | self.chk.fail( |
| 1684 | message_registry.CANNOT_INSTANTIATE_PROTOCOL.format(callee.type_object().name), |
| 1685 | context, |
| 1686 | ) |
| 1687 | elif ( |
| 1688 | callee.is_type_obj() |
| 1689 | and callee.type_object().is_abstract |
| 1690 | # Exception for Type[...] |
| 1691 | and not callee.from_type_type |
| 1692 | and not callee.type_object().fallback_to_any |
| 1693 | ): |
| 1694 | type = callee.type_object() |
| 1695 | # Determine whether the implicitly abstract attributes are functions with |
| 1696 | # None-compatible return types. |
| 1697 | abstract_attributes: dict[str, bool] = {} |
| 1698 | for attr_name, abstract_status in type.abstract_attributes: |
| 1699 | if abstract_status == IMPLICITLY_ABSTRACT: |
| 1700 | abstract_attributes[attr_name] = self.can_return_none(type, attr_name) |
| 1701 | else: |
| 1702 | abstract_attributes[attr_name] = False |
| 1703 | self.msg.cannot_instantiate_abstract_class( |
| 1704 | callee.type_object().name, abstract_attributes, context |
| 1705 | ) |
| 1706 | |
| 1707 | var_arg = callee.var_arg() |
| 1708 | if var_arg and isinstance(var_arg.typ, UnpackType): |
no test coverage detected