Skip to content

Commit

Permalink
stubgen can import Iterable and Iterator from typing (#9088)
Browse files Browse the repository at this point in the history
  • Loading branch information
AWhetter authored Aug 2, 2020
1 parent 12855d4 commit e6615c9
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion mypy/stubgenc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@
)


# Members of the typing module to consider for importing by default.
_DEFAULT_TYPING_IMPORTS = (
'Any'
'Dict',
'Iterable',
'Iterator',
'List',
'Optional',
'Tuple',
'Union',
)


def generate_stub_for_c_module(module_name: str,
target: str,
sigs: Optional[Dict[str, str]] = None,
Expand Down Expand Up @@ -82,7 +95,7 @@ def generate_stub_for_c_module(module_name: str,
def add_typing_import(output: List[str]) -> List[str]:
"""Add typing imports for collections/types that occur in the generated stub."""
names = []
for name in ['Any', 'Union', 'Tuple', 'Optional', 'List', 'Dict']:
for name in _DEFAULT_TYPING_IMPORTS:
if any(re.search(r'\b%s\b' % name, line) for line in output):
names.append(name)
if names:
Expand Down

0 comments on commit e6615c9

Please sign in to comment.