| [case testUnannotatedFunction] |
| # flags: --disallow-untyped-defs |
| def f(x): pass |
| [out] |
| main:2: error: Function is missing a type annotation |
| |
| [case testUnannotatedArgument] |
| # flags: --disallow-untyped-defs |
| def f(x) -> int: pass |
| [out] |
| main:2: error: Function is missing a type annotation for one or more arguments |
| |
| [case testUnannotatedArgumentWithFastParser] |
| # flags: --fast-parser --disallow-untyped-defs |
| def f(x) -> int: pass |
| [out] |
| main:2: error: Function is missing a type annotation for one or more arguments |
| |
| [case testNoArgumentFunction] |
| # flags: --disallow-untyped-defs |
| def f() -> int: pass |
| [out] |
| |
| [case testUnannotatedReturn] |
| # flags: --disallow-untyped-defs |
| def f(x: int): pass |
| [out] |
| main:2: error: Function is missing a return type annotation |
| |
| [case testUnannotatedReturnWithFastParser] |
| # flags: --fast-parser --disallow-untyped-defs |
| def f(x: int): pass |
| [out] |
| main:2: error: Function is missing a return type annotation |
| |
| [case testLambda] |
| # flags: --disallow-untyped-defs |
| lambda x: x |
| [out] |
| |
| [case testUntypedDef] |
| # flags: --disallow-untyped-defs |
| def f(): |
| 1 + "str" |
| [out] |
| main:2: error: Function is missing a type annotation |
| |
| [case testSubclassingAny] |
| # flags: --disallow-subclassing-any |
| from typing import Any |
| FakeClass = None # type: Any |
| class Foo(FakeClass): pass # E: Class cannot subclass 'FakeClass' (has type 'Any') |
| [out] |
| |
| [case testSubclassingAnyMultipleBaseClasses] |
| # flags: --disallow-subclassing-any |
| from typing import Any |
| FakeClass = None # type: Any |
| class ActualClass: pass |
| class Foo(ActualClass, FakeClass): pass # E: Class cannot subclass 'FakeClass' (has type 'Any') |
| [out] |
| |
| [case testSubclassingAnySilentImports] |
| # flags: --disallow-subclassing-any --follow-imports=skip |
| # cmd: mypy -m main |
| |
| [file main.py] |
| from ignored_module import BaseClass |
| class Foo(BaseClass): pass |
| |
| [file ignored_module.py] |
| class BaseClass: pass |
| |
| [out] |
| tmp/main.py:2: error: Class cannot subclass 'BaseClass' (has type 'Any') |
| |
| [case testSubclassingAnySilentImports2] |
| # flags: --disallow-subclassing-any --follow-imports=skip |
| # cmd: mypy -m main |
| |
| [file main.py] |
| import ignored_module |
| class Foo(ignored_module.BaseClass): pass |
| |
| [file ignored_module.py] |
| class BaseClass: pass |
| |
| [out] |
| tmp/main.py:2: error: Class cannot subclass 'BaseClass' (has type 'Any') |
| |
| [case testWarnNoReturnIgnoresTrivialFunctions] |
| # flags: --warn-no-return |
| def f() -> int: |
| pass |
| def g() -> int: |
| ... |
| def h() -> int: |
| """with docstring""" |
| pass |
| def i() -> int: |
| """with docstring""" |
| ... |
| def j() -> int: |
| u"""with unicode docstring""" |
| pass |
| def k() -> int: |
| """docstring only""" |
| |
| [case testWarnNoReturnWorksWithAlwaysTrue] |
| # flags: --warn-no-return |
| PY3 = True |
| def f() -> int: |
| if PY3: |
| return 0 |
| else: |
| return 0 |
| [builtins fixtures/bool.pyi] |
| |
| [case testWarnNoReturnWorksWithAlwaysFalse] |
| # flags: --warn-no-return |
| PY2 = False |
| def f() -> int: |
| if PY2: |
| return 0 |
| else: |
| return 0 |
| [builtins fixtures/bool.pyi] |
| |
| [case testWarnNoReturnWorksWithMypyTrue] |
| # flags: --warn-no-return |
| MYPY = False |
| def f() -> int: |
| if MYPY: |
| return 0 |
| else: |
| return 0 |
| [builtins fixtures/bool.pyi] |
| |
| [case testShowErrorContextFunction] |
| # flags: --show-error-context |
| def f() -> None: |
| 0 + "" |
| [out] |
| main: note: In function "f": |
| main:3: error: Unsupported operand types for + ("int" and "str") |
| |
| [case testShowErrorContextClass] |
| # flags: --show-error-context |
| class A: |
| 0 + "" |
| [out] |
| main: note: In class "A": |
| main:3: error: Unsupported operand types for + ("int" and "str") |
| |
| [case testShowErrorContextMember] |
| # flags: --show-error-context |
| class A: |
| def f(self, x: int) -> None: |
| self.f("") |
| [out] |
| main: note: In member "f" of class "A": |
| main:4: error: Argument 1 to "f" of "A" has incompatible type "str"; expected "int" |
| |
| [case testShowErrorContextModule] |
| # flags: --show-error-context |
| import m |
| [file m.py] |
| 0 + "" |
| [out] |
| main:2: note: In module imported here: |
| tmp/m.py:1: error: Unsupported operand types for + ("int" and "str") |
| |
| [case testShowErrorContextTopLevel] |
| # flags: --show-error-context |
| def f() -> None: |
| 0 + "" |
| 0 + "" |
| [out] |
| main: note: In function "f": |
| main:3: error: Unsupported operand types for + ("int" and "str") |
| main: note: At top level: |
| main:4: error: Unsupported operand types for + ("int" and "str") |
| |
| [case testShowErrorContextFromHere] |
| # flags: --show-error-context |
| import a |
| [file a.py] |
| import b |
| [file b.py] |
| 0 + "" |
| [out] |
| tmp/a.py:1: note: In module imported here, |
| main:2: note: ... from here: |
| tmp/b.py:1: error: Unsupported operand types for + ("int" and "str") |
| |
| [case testFollowImportsNormal] |
| # flags: --follow-imports=normal |
| from mod import x |
| x + "" |
| [file mod.py] |
| 1 + "" |
| x = 0 |
| [out] |
| tmp/mod.py:1: error: Unsupported operand types for + ("int" and "str") |
| main:3: error: Unsupported operand types for + ("int" and "str") |
| |
| [case testFollowImportsSilent] |
| # flags: --follow-imports=silent |
| from mod import x |
| x + "" # E: Unsupported operand types for + ("int" and "str") |
| [file mod.py] |
| 1 + "" |
| x = 0 |
| |
| [case testFollowImportsSkip] |
| # flags: --follow-imports=skip |
| from mod import x |
| x + "" |
| [file mod.py] |
| this deliberate syntax error will not be reported |
| [out] |
| |
| [case testFollowImportsError] |
| # flags: --follow-imports=error |
| from mod import x |
| x + "" |
| [file mod.py] |
| deliberate syntax error |
| [out] |
| main:2: note: Import of 'mod' ignored |
| main:2: note: (Using --follow-imports=error, module not passed on command line) |
| |
| [case testIgnoreMissingImportsFalse] |
| from mod import x |
| [out] |
| main:1: error: Cannot find module named 'mod' |
| main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help) |
| |
| [case testIgnoreMissingImportsTrue] |
| # flags: --ignore-missing-imports |
| from mod import x |
| [out] |