-
-
Notifications
You must be signed in to change notification settings - Fork 137
Open
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed
Description
We have almost completely re-invented how to get callable arguments by name, position, and type:
returns/returns/contrib/mypy/_typeops/transform_callable.py
Lines 63 to 97 in c243100
def _applied_positional_args( | |
self, | |
applied_args: List[FuncArg], | |
) -> List[FuncArg]: | |
callee_args = list(filter( | |
lambda name: name.name is None, # TODO: maybe use `kind` instead? | |
applied_args, | |
)) | |
new_function_args = [] | |
for ind, arg in enumerate(FuncArg.from_callable(self._case_function)): | |
if arg.kind in self._positional_kinds and ind < len(callee_args): | |
new_function_args.append(arg) | |
return new_function_args | |
def _applied_named_args( | |
self, | |
applied_args: List[FuncArg], | |
) -> List[FuncArg]: | |
callee_args = list(filter( | |
lambda name: name.name is not None, | |
applied_args, | |
)) | |
new_function_args = [] | |
for arg in FuncArg.from_callable(self._case_function): | |
has_named_arg_def = any( | |
# Argument can either be used as a named argument | |
# or passed to `**kwrgs` if it exists. | |
arg.name == rdc.name or arg.kind == ARG_STAR2 | |
for rdc in callee_args | |
) | |
if callee_args and has_named_arg_def: | |
new_function_args.append(arg) | |
return new_function_args |
But, mypy
already has this:
Maybe, we can reuse it?
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed