Skip to content

Consider refactoring #716

@sobolevn

Description

@sobolevn

We have almost completely re-invented how to get callable arguments by name, position, and type:

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:

https://github.com/python/mypy/blob/52702e588ad2b8702ad74888ea10df852af1f035/mypy/typeops.py#L289-L313

Maybe, we can reuse it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions