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

Function _get_argument

mypy/plugins/common.py:76–98  ·  view source on GitHub ↗

Return the expression for the specific argument.

(call: CallExpr, name: str)

Source from the content-addressed store, hash-verified

74
75
76def _get_argument(call: CallExpr, name: str) -> Expression | None:
77 """Return the expression for the specific argument."""
78 # To do this we use the CallableType of the callee to find the FormalArgument,
79 # then walk the actual CallExpr looking for the appropriate argument.
80 #
81 # Note: I'm not hard-coding the index so that in the future we can support other
82 # attrib and class makers.
83 callee_type = _get_callee_type(call)
84 if not callee_type:
85 return None
86
87 argument = callee_type.argument_by_name(name)
88 if not argument:
89 return None
90 assert argument.name
91
92 for i, (attr_name, attr_value) in enumerate(zip(call.arg_names, call.args)):
93 if argument.pos is not None and not attr_name and i == argument.pos:
94 return attr_value
95 if attr_name == argument.name:
96 return attr_value
97
98 return None
99
100
101def find_shallow_matching_overload_item(overload: Overloaded, call: CallExpr) -> CallableType:

Callers 3

_get_bool_argumentFunction · 0.85

Calls 4

_get_callee_typeFunction · 0.85
enumerateFunction · 0.85
zipFunction · 0.85
argument_by_nameMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…