|
2 | 2 |
|
3 | 3 | import itertools
|
4 | 4 | import contextlib
|
| 5 | +import os |
| 6 | +import os.path |
5 | 7 |
|
6 | 8 | from typing import (
|
7 | 9 | Any, Dict, Set, List, cast, Tuple, TypeVar, Union, Optional, NamedTuple
|
@@ -375,6 +377,7 @@ class TypeChecker(NodeVisitor[Type]):
|
375 | 377 | disallow_untyped_defs = False
|
376 | 378 | # Should we check untyped function defs?
|
377 | 379 | check_untyped_defs = False
|
| 380 | + is_typeshed_stub = False |
378 | 381 |
|
379 | 382 | def __init__(self, errors: Errors, modules: Dict[str, MypyFile],
|
380 | 383 | pyversion: Tuple[int, int] = defaults.PYTHON3_VERSION,
|
@@ -414,6 +417,8 @@ def visit_file(self, file_node: MypyFile, path: str) -> None:
|
414 | 417 | self.globals = file_node.names
|
415 | 418 | self.weak_opts = file_node.weak_opts
|
416 | 419 | self.enter_partial_types()
|
| 420 | + # gross, but no other clear way to tell |
| 421 | + self.is_typeshed_stub = self.is_stub and 'typeshed' in os.path.normpath(path).split(os.sep) |
417 | 422 |
|
418 | 423 | for d in file_node.defs:
|
419 | 424 | self.accept(d)
|
@@ -666,7 +671,7 @@ def check_func_def(self, defn: FuncItem, typ: CallableType, name: str) -> None:
|
666 | 671 | self.fail(messages.INIT_MUST_HAVE_NONE_RETURN_TYPE,
|
667 | 672 | item.type)
|
668 | 673 |
|
669 |
| - if self.disallow_untyped_defs: |
| 674 | + if self.disallow_untyped_defs and not self.is_typeshed_stub: |
670 | 675 | # Check for functions with unspecified/not fully specified types.
|
671 | 676 | def is_implicit_any(t: Type) -> bool:
|
672 | 677 | return isinstance(t, AnyType) and t.implicit
|
|
0 commit comments