Perform anal_type for arguments and return type when copying methods to another class (#279)

* Found the reproducible test case

* fix import resolution for method copy

* remove irrelevant parts from test

* fix mypy errors

Co-authored-by: Boger <kotvberloge@gmail.com>
This commit is contained in:
Maksim Kurnikov
2019-12-17 19:19:31 +03:00
committed by GitHub
parent 665f4d8ea1
commit 1196336e3b
2 changed files with 37 additions and 0 deletions

View File

@@ -327,6 +327,14 @@ def _prepare_new_method_arguments(node: FuncDef) -> Tuple[List[Argument], MypyTy
def copy_method_to_another_class(ctx: ClassDefContext, self_type: Instance,
new_method_name: str, method_node: FuncDef) -> None:
arguments, return_type = _prepare_new_method_arguments(method_node)
semanal_api = get_semanal_api(ctx)
for argument in arguments:
if argument.type_annotation is not None:
argument.type_annotation = semanal_api.anal_type(argument.type_annotation)
if return_type is not None:
return_type = semanal_api.anal_type(return_type) or AnyType(TypeOfAny.unannotated)
add_method(ctx,
new_method_name,
args=arguments,