Type check a call. Also infer type arguments if the callee is a generic function. Return (result type, inferred callee type). Arguments: callee: type of the called value args: actual argument expressions arg_kinds: contains nodes.ARG_* c
(
self,
callee: Type,
args: list[Expression],
arg_kinds: list[ArgKind],
context: Context,
arg_names: Sequence[str | None] | None = None,
callable_node: Expression | None = None,
callable_name: str | None = None,
object_type: Type | None = None,
original_type: Type | None = None,
)
| 1527 | return make_simplified_union(res) |
| 1528 | |
| 1529 | def check_call( |
| 1530 | self, |
| 1531 | callee: Type, |
| 1532 | args: list[Expression], |
| 1533 | arg_kinds: list[ArgKind], |
| 1534 | context: Context, |
| 1535 | arg_names: Sequence[str | None] | None = None, |
| 1536 | callable_node: Expression | None = None, |
| 1537 | callable_name: str | None = None, |
| 1538 | object_type: Type | None = None, |
| 1539 | original_type: Type | None = None, |
| 1540 | ) -> tuple[Type, Type]: |
| 1541 | """Type check a call. |
| 1542 | |
| 1543 | Also infer type arguments if the callee is a generic function. |
| 1544 | |
| 1545 | Return (result type, inferred callee type). |
| 1546 | |
| 1547 | Arguments: |
| 1548 | callee: type of the called value |
| 1549 | args: actual argument expressions |
| 1550 | arg_kinds: contains nodes.ARG_* constant for each argument in args |
| 1551 | describing whether the argument is positional, *arg, etc. |
| 1552 | context: current expression context, used for inference. |
| 1553 | arg_names: names of arguments (optional) |
| 1554 | callable_node: associate the inferred callable type to this node, |
| 1555 | if specified |
| 1556 | callable_name: Fully-qualified name of the function/method to call, |
| 1557 | or None if unavailable (examples: 'builtins.open', 'typing.Mapping.get') |
| 1558 | object_type: If callable_name refers to a method, the type of the object |
| 1559 | on which the method is being called |
| 1560 | """ |
| 1561 | callee = get_proper_type(callee) |
| 1562 | |
| 1563 | if isinstance(callee, CallableType): |
| 1564 | if callee.variables: |
| 1565 | overloaded = self.is_generic_decorator_overload_call(callee, args) |
| 1566 | if overloaded is not None: |
| 1567 | # Special casing for inline application of generic callables to overloads. |
| 1568 | # Supporting general case would be tricky, but this should cover 95% of cases. |
| 1569 | overloaded_result = self.handle_decorator_overload_call( |
| 1570 | callee, overloaded, context |
| 1571 | ) |
| 1572 | if overloaded_result is not None: |
| 1573 | return overloaded_result |
| 1574 | |
| 1575 | return self.check_callable_call( |
| 1576 | callee, |
| 1577 | args, |
| 1578 | arg_kinds, |
| 1579 | context, |
| 1580 | arg_names, |
| 1581 | callable_node, |
| 1582 | callable_name, |
| 1583 | object_type, |
| 1584 | ) |
| 1585 | elif isinstance(callee, Overloaded): |
| 1586 | return self.check_overload_call( |