@@ -79,6 +79,13 @@ async def g(x: int) -> Any:
79
79
[builtins fixtures/async_await.pyi]
80
80
[typing fixtures/typing-async.pyi]
81
81
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
+
82
89
[case testDisallowUntypedDefsUntypedDecorator]
83
90
# flags: --disallow-untyped-decorators
84
91
def d(p):
@@ -540,21 +547,30 @@ tmp/b.py:1: error: Unsupported operand types for + ("int" and "str")
540
547
[case testFollowImportsNormal]
541
548
# flags: --follow-imports=normal
542
549
from 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")
544
557
[file mod.py]
545
- 1 + ""
558
+ 1 + "" # E: Unsupported operand types for + ("int" and "str")
546
559
x = 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")
550
561
551
562
[case testFollowImportsSilent]
552
563
# flags: --follow-imports=silent
553
564
from mod import x
554
565
x + "" # 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")
555
570
[file mod.py]
556
571
1 + ""
557
572
x = 0
573
+ x += ""
558
574
559
575
[case testFollowImportsSilentTypeIgnore]
560
576
# flags: --warn-unused-ignores --follow-imports=silent
@@ -565,20 +581,55 @@ x = 3 # type: ignore
565
581
[case testFollowImportsSkip]
566
582
# flags: --follow-imports=skip
567
583
from mod import x
584
+ reveal_type(x) # N: Revealed type is "Any"
568
585
x + ""
586
+ import mod
587
+ reveal_type(mod.x) # N: Revealed type is "Any"
569
588
[file mod.py]
570
589
this deliberate syntax error will not be reported
571
- [out]
572
590
573
591
[case testFollowImportsError]
574
592
# 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)
576
595
x + ""
596
+ reveal_type(x) # N: Revealed type is "Any"
597
+ import mod
598
+ reveal_type(mod.x) # N: Revealed type is "Any"
577
599
[file mod.py]
578
600
deliberate 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
582
633
583
634
[case testIgnoreMissingImportsFalse]
584
635
from mod import x
@@ -591,6 +642,15 @@ main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missin
591
642
from mod import x
592
643
[out]
593
644
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
+
594
654
[case testPerFileIncompleteDefsBasic]
595
655
# flags: --config-file tmp/mypy.ini
596
656
import standard, incomplete
@@ -868,6 +928,16 @@ implicit_optional = true
868
928
module = 'optional'
869
929
strict_optional = true
870
930
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"
871
941
872
942
[case testDisallowImplicitTypesIgnoreMissingTypes]
873
943
# flags: --ignore-missing-imports --disallow-any-unimported
@@ -1447,6 +1517,29 @@ class Queue(Generic[_T]): ...
1447
1517
[builtins fixtures/async_await.pyi]
1448
1518
[typing fixtures/typing-full.pyi]
1449
1519
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]
1450
1543
1451
1544
[case testCheckDefaultAllowAnyGeneric]
1452
1545
from typing import TypeVar, Callable
@@ -1863,8 +1956,9 @@ x: Tuple = () # E: Missing type parameters for generic type "Tuple"
1863
1956
# flags: --disallow-any-generics
1864
1957
from typing import Tuple, List
1865
1958
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
1868
1962
[builtins fixtures/list.pyi]
1869
1963
1870
1964
[case testDisallowAnyGenericsTypeType]
@@ -1908,14 +2002,36 @@ x: A = ('a', 'b', 1) # E: Missing type parameters for generic type "A"
1908
2002
from typing import List
1909
2003
1910
2004
def 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
1912
2006
def h(l: List[List]) -> None: pass # E: Missing type parameters for generic type "List"
1913
2007
def 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"
1914
2009
1915
2010
x = [] # E: Need type annotation for "x" (hint: "x: List[<type>] = ...")
1916
2011
y: List = [] # E: Missing type parameters for generic type "List"
1917
2012
[builtins fixtures/list.pyi]
1918
2013
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
+
1919
2035
[case testDisallowAnyGenericsCustomGenericClass]
1920
2036
# flags: --disallow-any-generics
1921
2037
from typing import Generic, TypeVar, Any
@@ -2162,6 +2278,38 @@ allow_untyped_defs = True
2162
2278
allow_untyped_calls = True
2163
2279
disable_error_code = var-annotated
2164
2280
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
+
2165
2313
[case testPerModuleErrorCodesOverride]
2166
2314
# flags: --config-file tmp/mypy.ini
2167
2315
import tests.foo
@@ -2284,3 +2432,8 @@ class C(Generic[T]): ...
2284
2432
2285
2433
A = Union[C, List] # OK
2286
2434
[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