8000 Suppress untyped defs error in typeshed stubs (#1554) · python/mypy@88b0098 · GitHub
[go: up one dir, main page]

Skip to content

Commit 88b0098

Browse files
committed
Suppress untyped defs error in typeshed stubs (#1554)
* Suppress untyped defs error in typeshed stubs * change name
1 parent 8472677 commit 88b0098

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

mypy/checker.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import itertools
44
import contextlib
5+
import os
6+
import os.path
57

68
from typing import (
79
Any, Dict, Set, List, cast, Tuple, TypeVar, Union, Optional, NamedTuple
@@ -375,6 +377,7 @@ class TypeChecker(NodeVisitor[Type]):
375377
disallow_untyped_defs = False
376378
# Should we check untyped function defs?
377379
check_untyped_defs = False
380+
is_typeshed_stub = False
378381

379382
def __init__(self, errors: Errors, modules: Dict[str, MypyFile],
380383
pyversion: Tuple[int, int] = defaults.PYTHON3_VERSION,
@@ -414,6 +417,8 @@ def visit_file(self, file_node: MypyFile, path: str) -> None:
414417
self.globals = file_node.names
415418
self.weak_opts = file_node.weak_opts
416419
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)
417422

418423
for d in file_node.defs:
419424
self.accept(d)
@@ -666,7 +671,7 @@ def check_func_def(self, defn: FuncItem, typ: CallableType, name: str) -> None:
666671
self.fail(messages.INIT_MUST_HAVE_NONE_RETURN_TYPE,
667672
item.type)
668673

669-
if self.disallow_untyped_defs:
674+
if self.disallow_untyped_defs and not self.is_typeshed_stub:
670675
# Check for functions with unspecified/not fully specified types.
671676
def is_implicit_any(t: Type) -> bool:
672677
return isinstance(t, AnyType) and t.implicit

0 commit comments

Comments
 (0)
0