class documentation

class ArgTypeExpander: (source)

View In Hierarchy

Utility class for mapping actual argument types to formal arguments. One of the main responsibilities is to expand caller tuple *args and TypedDict **kwargs, and to keep track of which tuple/TypedDict items have already been consumed. Example: def f(x: int, *args: str) -> None: ... f(*(1, 'x', 1.1)) We'd call expand_actual_type three times: 1. The first call would provide 'int' as the actual type of 'x' (from '1'). 2. The second call would provide 'str' as one of the actual types for '*args'. 2. The third call would provide 'float' as one of the actual types for '*args'. A single instance can process all the arguments for a single call. Each call needs a separate instance since instances have per-call state.

Method __init__ Undocumented
Method expand_actual_type Return the actual (caller) type(s) of a formal argument with the given kinds.
Instance Variable context Undocumented
Instance Variable kwargs_used Undocumented
Instance Variable tuple_index Undocumented
def __init__(self, context: ArgumentInferContext): (source)

Undocumented

def expand_actual_type(self, actual_type: Type, actual_kind: nodes.ArgKind, formal_name: str|None, formal_kind: nodes.ArgKind) -> Type: (source)

Return the actual (caller) type(s) of a formal argument with the given kinds. If the actual argument is a tuple *args, return the next individual tuple item that maps to the formal arg. If the actual argument is a TypedDict **kwargs, return the next matching typed dict value type based on formal argument name and kind. This is supposed to be called for each formal, in order. Call multiple times per formal if multiple actuals map to a formal.

Undocumented

kwargs_used: set[str] = (source)

Undocumented

tuple_index: int = (source)

Undocumented