MCPcopy
hub / github.com/python/mypy / formal_arguments

Method formal_arguments

mypy/types.py:2341–2362  ·  view source on GitHub ↗

Return a list of the formal arguments of this callable, ignoring *arg and **kwargs. To handle *args and **kwargs, use the 'callable.var_args' and 'callable.kw_args' fields, if they are not None. If you really want to include star args in the yielded output, set the

(self, include_star_args: bool = False)

Source from the content-addressed store, hash-verified

2339 return sum(kind.is_positional() for kind in self.arg_kinds)
2340
2341 def formal_arguments(self, include_star_args: bool = False) -> list[FormalArgument]:
2342 """Return a list of the formal arguments of this callable, ignoring *arg and **kwargs.
2343
2344 To handle *args and **kwargs, use the 'callable.var_args' and 'callable.kw_args' fields,
2345 if they are not None.
2346
2347 If you really want to include star args in the yielded output, set the
2348 'include_star_args' parameter to 'True'."""
2349 args = []
2350 done_with_positional = False
2351 for i in range(len(self.arg_types)):
2352 kind = self.arg_kinds[i]
2353 if kind.is_named() or kind.is_star():
2354 done_with_positional = True
2355 if not include_star_args and kind.is_star():
2356 continue
2357
2358 required = kind.is_required()
2359 pos = None if done_with_positional else i
2360 arg = FormalArgument(self.arg_names[i], pos, self.arg_types[i], required)
2361 args.append(arg)
2362 return args
2363
2364 def argument_by_name(self, name: str | None) -> FormalArgument | None:
2365 if name is None:

Callers

nothing calls this directly

Calls 7

rangeClass · 0.85
lenFunction · 0.85
FormalArgumentClass · 0.85
is_namedMethod · 0.80
is_starMethod · 0.80
is_requiredMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected