Skip to content

stubgen: Use _typeshed.Incomplete instead of typing.Any #12449

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 1 commit into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
29 changes: 15 additions & 14 deletions mypy/stubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ def visit_mypy_file(self, o: MypyFile) -> None:
self.defined_names = find_defined_names(o)
self.referenced_names = find_referenced_names(o)
known_imports = {
"_typeshed": ["Incomplete"],
"typing": ["Any", "TypeVar"],
"collections.abc": ["Generator"],
}
Expand Down Expand Up @@ -689,14 +690,14 @@ def visit_func_def(self, o: FuncDef, is_abstract: bool = False,
return_name = 'None'
for expr, in_assignment in all_yield_expressions(o):
if expr.expr is not None and not self.is_none_expr(expr.expr):
self.add_typing_import('Any')
yield_name = 'Any'
self.add_typing_import('Incomplete')
yield_name = 'Incomplete'
if in_assignment:
self.add_typing_import('Any')
send_name = 'Any'
self.add_typing_import('Incomplete')
send_name = 'Incomplete'
if has_return_statement(o):
self.add_typing_import('Any')
return_name = 'Any'
self.add_typing_import('Incomplete')
return_name = 'Incomplete'
generator_name = self.typing_name('Generator')
retname = f'{generator_name}[{yield_name}, {send_name}, {return_name}]'
elif not has_return_statement(o) and not is_abstract:
Expand Down Expand Up @@ -954,18 +955,18 @@ def process_namedtuple(self, lvalue: NameExpr, rvalue: CallExpr) -> None:
list_items = cast(List[StrExpr], rvalue.args[1].items)
items = [item.value for item in list_items]
else:
self.add('%s%s: Any' % (self._indent, lvalue.name))
self.import_tracker.require_name('Any')
self.add('%s%s: Incomplete' % (self._indent, lvalue.name))
self.import_tracker.require_name('Incomplete')
return
self.import_tracker.require_name('NamedTuple')
self.add('{}class {}(NamedTuple):'.format(self._indent, lvalue.name))
if len(items) == 0:
self.add(' ...\n')
else:
self.import_tracker.require_name('Any')
self.import_tracker.require_name('Incomplete')
self.add('\n')
for item in items:
self.add('{} {}: Any\n'.format(self._indent, item))
self.add('{} {}: Incomplete\n'.format(self._indent, item))
self._state = CLASS

def is_alias_expression(self, expr: Expression, top_level: bool = True) -> bool:
Expand Down Expand Up @@ -1220,11 +1221,11 @@ def get_str_type_of_node(self, rvalue: Expression,
return 'bool'
if can_infer_optional and \
isinstance(rvalue, NameExpr) and rvalue.name == 'None':
self.add_typing_import('Any')
return '{} | None'.format(self.typing_name('Any'))
self.add_typing_import('Incomplete')
return '{} | None'.format(self.typing_name('Incomplete'))
if can_be_any:
self.add_typing_import('Any')
return self.typing_name('Any')
self.add_typing_import('Incomplete')
return self.typing_name('Incomplete')
else:
return ''

Expand Down
Loading