Skip to content

Commit

Permalink
reduce the diff
Browse files Browse the repository at this point in the history
  • Loading branch information
chadrik committed Aug 2, 2023
1 parent db1ba63 commit c04dc0c
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions mypy/stubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,39 +501,39 @@ def _get_func_args(self, o: FuncDef, ctx: FunctionContext) -> list[ArgSig]:
args.append(ArgSig(name, typename, default=bool(arg_.initializer)))
return args

def _get_func_return(self, func_def: FuncDef, ctx: FunctionContext) -> str | None:
if func_def.name != "__init__" and isinstance(func_def.unanalyzed_type, CallableType):
if isinstance(get_proper_type(func_def.unanalyzed_type.ret_type), AnyType):
def _get_func_return(self, o: FuncDef, ctx: FunctionContext) -> str | None:
if o.name != "__init__" and isinstance(o.unanalyzed_type, CallableType):
if isinstance(get_proper_type(o.unanalyzed_type.ret_type), AnyType):
# Luckily, a return type explicitly annotated with "Any" has
# type "UnboundType" and will enter the else branch.
return None # implicit Any
else:
return self.print_annotation(func_def.unanalyzed_type.ret_type)
if func_def.abstract_status == IS_ABSTRACT or func_def.name in METHODS_WITH_RETURN_VALUE:
return self.print_annotation(o.unanalyzed_type.ret_type)
if o.abstract_status == IS_ABSTRACT or o.name in METHODS_WITH_RETURN_VALUE:
# Always assume abstract methods return Any unless explicitly annotated. Also
# some dunder methods should not have a None return type.
return None # implicit Any
retname = infer_method_ret_type(func_def.name)
retname = infer_method_ret_type(o.name)
if retname is not None:
return retname
if has_yield_expression(func_def) or has_yield_from_expression(func_def):
if has_yield_expression(o) or has_yield_from_expression(o):
self.add_typing_import("Generator")
yield_name = "None"
send_name = "None"
return_name = "None"
if has_yield_from_expression(func_def):
if has_yield_from_expression(o):
yield_name = send_name = self.add_typing_import("Incomplete")
else:
for expr, in_assignment in all_yield_expressions(func_def):
for expr, in_assignment in all_yield_expressions(o):
if expr.expr is not None and not is_none_expr(expr.expr):
yield_name = self.add_obj_import("_typeshed", "Incomplete", require=True)
if in_assignment:
send_name = self.add_obj_import("_typeshed", "Incomplete", require=True)
if has_return_statement(func_def):
if has_return_statement(o):
return_name = self.add_obj_import("_typeshed", "Incomplete", require=True)
generator_name = self.add_typing_import("Generator")
return f"{generator_name}[{yield_name}, {send_name}, {return_name}]"
if not has_return_statement(func_def) and func_def.abstract_status == NOT_ABSTRACT:
if not has_return_statement(o) and o.abstract_status == NOT_ABSTRACT:
return "None"
return None

Expand Down

0 comments on commit c04dc0c

Please sign in to comment.