@@ -79,6 +79,13 @@ async def g(x: int) -> Any:
7979[builtins fixtures/async_await.pyi]
8080[typing fixtures/typing-async.pyi]
8181
82+ [case testDisallowUntypedDefsAndGeneric]
83+ # flags: --disallow-untyped-defs --disallow-any-generics
84+ def get_tasks(self):
85+ return 'whatever'
86+ [out]
87+ main:2: error: Function is missing a return type annotation
88+
8289[case testDisallowUntypedDefsUntypedDecorator]
8390# flags: --disallow-untyped-decorators
8491def d(p):
@@ -540,21 +547,30 @@ tmp/b.py:1: error: Unsupported operand types for + ("int" and "str")
540547[case testFollowImportsNormal]
541548# flags: --follow-imports=normal
542549from mod import x
543- x + ""
550+ x + 0
551+ x + "" # E: Unsupported operand types for + ("int" and "str")
552+ import mod
553+ mod.x + 0
554+ mod.x + "" # E: Unsupported operand types for + ("int" and "str")
555+ mod.y # E: "object" has no attribute "y"
556+ mod + 0 # E: Unsupported left operand type for + ("object")
544557[file mod.py]
545- 1 + ""
558+ 1 + "" # E: Unsupported operand types for + ("int" and "str")
546559x = 0
547- [out]
548- tmp/mod.py:1: error: Unsupported operand types for + ("int" and "str")
549- main:3: error: Unsupported operand types for + ("int" and "str")
560+ x += "" # E: Unsupported operand types for + ("int" and "str")
550561
551562[case testFollowImportsSilent]
552563# flags: --follow-imports=silent
553564from mod import x
554565x + "" # E: Unsupported operand types for + ("int" and "str")
566+ import mod
567+ mod.x + "" # E: Unsupported operand types for + ("int" and "str")
568+ mod.y # E: "object" has no attribute "y"
569+ mod + 0 # E: Unsupported left operand type for + ("object")
555570[file mod.py]
5565711 + ""
557572x = 0
573+ x += ""
558574
559575[case testFollowImportsSilentTypeIgnore]
560576# flags: --warn-unused-ignores --follow-imports=silent
@@ -565,20 +581,55 @@ x = 3 # type: ignore
565581[case testFollowImportsSkip]
566582# flags: --follow-imports=skip
567583from mod import x
584+ reveal_type(x) # N: Revealed type is "Any"
568585x + ""
586+ import mod
587+ reveal_type(mod.x) # N: Revealed type is "Any"
569588[file mod.py]
570589this deliberate syntax error will not be reported
571- [out]
572590
573591[case testFollowImportsError]
574592# flags: --follow-imports=error
575- from mod import x
593+ from mod import x # E: Import of "mod" ignored \
594+ # N: (Using --follow-imports=error, module not passed on command line)
576595x + ""
596+ reveal_type(x) # N: Revealed type is "Any"
597+ import mod
598+ reveal_type(mod.x) # N: Revealed type is "Any"
577599[file mod.py]
578600deliberate syntax error
579- [out]
580- main:2: error: Import of "mod" ignored
581- main:2: note: (Using --follow-imports=error, module not passed on command line)
601+
602+ [case testFollowImportsSelective]
603+ # flags: --config-file tmp/mypy.ini
604+ import normal
605+ import silent
606+ import skip
607+ import error # E: Import of "error" ignored \
608+ # N: (Using --follow-imports=error, module not passed on command line)
609+ reveal_type(normal.x) # N: Revealed type is "builtins.int"
610+ reveal_type(silent.x) # N: Revealed type is "builtins.int"
611+ reveal_type(skip) # N: Revealed type is "Any"
612+ reveal_type(error) # N: Revealed type is "Any"
613+ [file mypy.ini]
614+ \[mypy]
615+ \[mypy-normal]
616+ follow_imports = normal
617+ \[mypy-silent]
618+ follow_imports = silent
619+ \[mypy-skip]
620+ follow_imports = skip
621+ \[mypy-error]
622+ follow_imports = error
623+ [file normal.py]
624+ x = 0
625+ x += '' # E: Unsupported operand types for + ("int" and "str")
626+ [file silent.py]
627+ x = 0
628+ x += ''
629+ [file skip.py]
630+ bla bla
631+ [file error.py]
632+ bla bla
582633
583634[case testIgnoreMissingImportsFalse]
584635from mod import x
@@ -591,6 +642,15 @@ main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missin
591642from mod import x
592643[out]
593644
645+ [case testNoConfigFile]
646+ # flags: --config-file=
647+ # type: ignore
648+
649+ [file mypy.ini]
650+ \[mypy]
651+ warn_unused_ignores = True
652+ [out]
653+
594654[case testPerFileIncompleteDefsBasic]
595655# flags: --config-file tmp/mypy.ini
596656import standard, incomplete
@@ -868,6 +928,16 @@ implicit_optional = true
868928module = 'optional'
869929strict_optional = true
870930
931+ [case testSilentMissingImportsOff]
932+ -- ignore_missing_imports is False by default.
933+ import missing # E: Cannot find implementation or library stub for module named "missing" \
934+ # N: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
935+ reveal_type(missing.x) # N: Revealed type is "Any"
936+
937+ [case testSilentMissingImportsOn]
938+ # flags: --ignore-missing-imports
939+ import missing
940+ reveal_type(missing.x) # N: Revealed type is "Any"
871941
872942[case testDisallowImplicitTypesIgnoreMissingTypes]
873943# flags: --ignore-missing-imports --disallow-any-unimported
@@ -1447,6 +1517,29 @@ class Queue(Generic[_T]): ...
14471517[builtins fixtures/async_await.pyi]
14481518[typing fixtures/typing-full.pyi]
14491519
1520+ [case testDisallowAnyGenericsBuiltinTuplePre39]
1521+ # flags: --disallow-any-generics --python-version 3.8
1522+ s = tuple([1, 2, 3])
1523+ def f(t: tuple) -> None: pass # E: Implicit generic "Any". Use "typing.Tuple" and specify generic parameters
1524+ [builtins fixtures/tuple.pyi]
1525+
1526+ [case testDisallowAnyGenericsBuiltinListPre39]
1527+ # flags: --disallow-any-generics --python-version 3.8
1528+ l = list([1, 2, 3])
1529+ def f(t: list) -> None: pass # E: Implicit generic "Any". Use "typing.List" and specify generic parameters
1530+ [builtins fixtures/list.pyi]
1531+
1532+ [case testDisallowAnyGenericsBuiltinSetPre39]
1533+ # flags: --disallow-any-generics --python-version 3.8
1534+ l = set({1, 2, 3})
1535+ def f(s: set) -> None: pass # E: Implicit generic "Any". Use "typing.Set" and specify generic parameters
1536+ [builtins fixtures/set.pyi]
1537+
1538+ [case testDisallowAnyGenericsBuiltinDictPre39]
1539+ # flags: --disallow-any-generics --python-version 3.8
1540+ l = dict([('a', 1)])
1541+ def f(d: dict) -> None: pass # E: Implicit generic "Any". Use "typing.Dict" and specify generic parameters
1542+ [builtins fixtures/dict.pyi]
14501543
14511544[case testCheckDefaultAllowAnyGeneric]
14521545from typing import TypeVar, Callable
@@ -1863,8 +1956,9 @@ x: Tuple = () # E: Missing type parameters for generic type "Tuple"
18631956# flags: --disallow-any-generics
18641957from typing import Tuple, List
18651958
1866- def f(s: List[Tuple]) -> None: pass # E: Missing type parameters for generic type "Tuple"
1867- def g(s: List[Tuple[str, str]]) -> None: pass # no error
1959+ def f(s: Tuple) -> None: pass # E: Missing type parameters for generic type "Tuple"
1960+ def g(s: List[Tuple]) -> None: pass # E: Missing type parameters for generic type "Tuple"
1961+ def h(s: List[Tuple[str, str]]) -> None: pass # no error
18681962[builtins fixtures/list.pyi]
18691963
18701964[case testDisallowAnyGenericsTypeType]
@@ -1908,14 +2002,36 @@ x: A = ('a', 'b', 1) # E: Missing type parameters for generic type "A"
19082002from typing import List
19092003
19102004def f(l: List) -> None: pass # E: Missing type parameters for generic type "List"
1911- def g(l: List[str]) -> None: pass # no error
2005+ def g(l: List[str]) -> None: pass
19122006def h(l: List[List]) -> None: pass # E: Missing type parameters for generic type "List"
19132007def i(l: List[List[List[List]]]) -> None: pass # E: Missing type parameters for generic type "List"
2008+ def j() -> List: pass # E: Missing type parameters for generic type "List"
19142009
19152010x = [] # E: Need type annotation for "x" (hint: "x: List[<type>] = ...")
19162011y: List = [] # E: Missing type parameters for generic type "List"
19172012[builtins fixtures/list.pyi]
19182013
2014+ [case testDisallowAnyGenericsPlainDict]
2015+ # flags: --disallow-any-generics
2016+ from typing import List, Dict
2017+
2018+ def f(d: Dict) -> None: pass # E: Missing type parameters for generic type "Dict"
2019+ def g(d: Dict[str, Dict]) -> None: pass # E: Missing type parameters for generic type "Dict"
2020+ def h(d: List[Dict]) -> None: pass # E: Missing type parameters for generic type "Dict"
2021+
2022+ d: Dict = {} # E: Missing type parameters for generic type "Dict"
2023+ [builtins fixtures/dict.pyi]
2024+
2025+ [case testDisallowAnyGenericsPlainSet]
2026+ # flags: --disallow-any-generics
2027+ from typing import Set
2028+
2029+ def f(s: Set) -> None: pass # E: Missing type parameters for generic type "Set"
2030+ def g(s: Set[Set]) -> None: pass # E: Missing type parameters for generic type "Set"
2031+
2032+ s: Set = set() # E: Missing type parameters for generic type "Set"
2033+ [builtins fixtures/set.pyi]
2034+
19192035[case testDisallowAnyGenericsCustomGenericClass]
19202036# flags: --disallow-any-generics
19212037from typing import Generic, TypeVar, Any
@@ -2162,6 +2278,38 @@ allow_untyped_defs = True
21622278allow_untyped_calls = True
21632279disable_error_code = var-annotated
21642280
2281+ [case testPerFileIgnoreErrors]
2282+ # flags: --config-file tmp/mypy.ini
2283+ import foo, bar
2284+ [file foo.py]
2285+ x: str = 5
2286+ [file bar.py]
2287+ x: str = 5 # E: Incompatible types in assignment (expression has type "int", variable has type "str")
2288+ [file mypy.ini]
2289+ \[mypy]
2290+ \[mypy-foo]
2291+ ignore_errors = True
2292+
2293+ [case testPerFileUntypedDefs]
2294+ # flags: --config-file tmp/mypy.ini
2295+ import x, y, z
2296+ [file x.py]
2297+ def f(a): ... # E: Function is missing a type annotation
2298+ def g(a: int) -> int: return f(a)
2299+ [file y.py]
2300+ def f(a): pass
2301+ def g(a: int) -> int: return f(a)
2302+ [file z.py]
2303+ def f(a): pass # E: Function is missing a type annotation
2304+ def g(a: int) -> int: return f(a) # E: Call to untyped function "f" in typed context
2305+ [file mypy.ini]
2306+ \[mypy]
2307+ disallow_untyped_defs = True
2308+ \[mypy-y]
2309+ disallow_untyped_defs = False
2310+ \[mypy-z]
2311+ disallow_untyped_calls = True
2312+
21652313[case testPerModuleErrorCodesOverride]
21662314# flags: --config-file tmp/mypy.ini
21672315import tests.foo
@@ -2284,3 +2432,8 @@ class C(Generic[T]): ...
22842432
22852433A = Union[C, List] # OK
22862434[builtins fixtures/list.pyi]
2435+
2436+ [case testNotesOnlyResultInExitSuccess]
2437+ -- check_untyped_defs is False by default.
2438+ def f():
2439+ x: int = "no" # N: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs
0 commit comments