8000 stubgen: Don't annotate unknown argument and return types by srittau · Pull Request #10626 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

stubgen: Don't annotate unknown argument and return types #10626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 11, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use get_proper_type()
  • Loading branch information
srittau committed Jun 11, 2021
commit f2dfba445518ddf80403f3f6cafec043ee6d7e2a
16 changes: 8 additions & 8 deletions mypy/stubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
from mypy.options import Options as MypyOptions
from mypy.types import (
Type, TypeStrVisitor, CallableType, UnboundType, NoneType, TupleType, TypeList, Instance,
AnyType
AnyType, get_proper_type
)
from mypy.visitor import NodeVisitor
from mypy.find_sources import create_source_list, InvalidSourceList
Expand Down Expand Up @@ -624,13 +624,13 @@ def visit_func_def(self, o: FuncDef, is_abstract: bool = False,
# name their 0th argument other than self/cls
is_self_arg = i == 0 and name == 'self'
is_cls_arg = i == 0 and name == 'cls'
if annotated_type and not isinstance(annotated_type, AnyType) and \
not is_self_arg and not is_cls_arg:
annotation = ""
if annotated_type and not is_self_arg and not is_cls_arg:
print(annotated_type, get_proper_type(annotated_type))
# Luckily, an argument explicitly annotated with "Any" has
# type "UnboundType" and will enter the else branch.
annotation = ": {}".format(self.print_annotation(annotated_type))
else:
annotation = ""
# type "UnboundType" and will not match.
if not isinstance(get_proper_type(annotated_type), AnyType):
annotation = ": {}".format(self.print_annotation(annotated_type))
if arg_.initializer:
if kind in (ARG_NAMED, ARG_NAMED_OPT) and not any(arg.startswith('*')
for arg in args):
Expand All @@ -653,7 +653,7 @@ def visit_func_def(self, o: FuncDef, is_abstract: bool = False,
args.append(arg)
retname = None
if o.name != '__init__' and isinstance(o.unanalyzed_type, CallableType):
if isinstance(o.unanalyzed_type.ret_type, AnyType):
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.
retname = None # implicit Any
Expand Down
0