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

Method param_spec

mypy/types.py:2423–2440  ·  view source on GitHub ↗

Return ParamSpec if callable can be called with one. A Callable accepting ParamSpec P args (*args, **kwargs) must have the two final parameters like this: *args: P.args, **kwargs: P.kwargs.

(self)

Source from the content-addressed store, hash-verified

2421 return a
2422
2423 def param_spec(self) -> ParamSpecType | None:
2424 """Return ParamSpec if callable can be called with one.
2425
2426 A Callable accepting ParamSpec P args (*args, **kwargs) must have the
2427 two final parameters like this: *args: P.args, **kwargs: P.kwargs.
2428 """
2429 if len(self.arg_types) < 2:
2430 return None
2431 if self.arg_kinds[-2] != ARG_STAR or self.arg_kinds[-1] != ARG_STAR2:
2432 return None
2433 arg_type = self.arg_types[-2]
2434 if not isinstance(arg_type, ParamSpecType):
2435 return None
2436
2437 # Prepend prefix for def f(prefix..., *args: P.args, **kwargs: P.kwargs) -> ...
2438 # TODO: confirm that all arg kinds are positional
2439 prefix = Parameters(self.arg_types[:-2], self.arg_kinds[:-2], self.arg_names[:-2])
2440 return arg_type.copy_modified(flavor=ParamSpecFlavor.BARE, prefix=prefix)
2441
2442 def normalize_trivial_unpack(self) -> None:
2443 # Normalize trivial unpack in var args as *args: *tuple[X, ...] -> *args: X in place.

Callers 13

check_callable_callMethod · 0.80
get_arg_infer_passesMethod · 0.80
check_argument_countMethod · 0.80
visit_callable_typeMethod · 0.80
visit_callable_typeMethod · 0.80
apply_generic_argumentsFunction · 0.80
format_type_innerFunction · 0.80
visit_callable_typeMethod · 0.80

Calls 4

lenFunction · 0.85
isinstanceFunction · 0.85
ParametersClass · 0.85
copy_modifiedMethod · 0.45

Tested by

no test coverage detected