Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 170 additions & 0 deletions test-data/unit/check-flags.test
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,176 @@ bla bla
[file error.py]
bla bla

[case testFlagsFile]
# flags: @tmp/flagsfile
x: int
FLAG = False
if not FLAG:
x = "unreachable"
[file flagsfile]
----always-true=FLAG

[case testConfigFile]
# flags: --config-file tmp/mypy.ini
x: int
FLAG = False
if not FLAG:
x = "unreachable"
[file mypy.ini]
\[mypy]
always_true = FLAG

[case testAltConfigFile]
# flags: --config-file tmp/config.ini
x: int
FLAG = False
if not FLAG:
x = "unreachable"
[file config.ini]
\[mypy]
always_true = FLAG

[case testMultipleGlobConfigSection]
# flags: --config-file tmp/mypy.ini
import x, y, z
[file mypy.ini]
\[mypy]
\[mypy-x.*,z.*]
disallow_untyped_defs = True
[file x.py]
def f(a): pass # E: Function is missing a type annotation
[file y.py]
def f(a): pass
[file z.py]
def f(a): pass # E: Function is missing a type annotation

[case testConfigMypyPath]
# flags: --config-file tmp/mypy.ini
import no_stubs # E: Cannot find implementation or library stub for module named "no_stubs" \
# N: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
from foo import foo
from bar import bar
from baz import baz
baz(bar(foo(42)))
baz(bar(foo('oof'))) # E: Argument 1 to "foo" has incompatible type "str"; expected "int"
[file mypy.ini]
\[mypy]
mypy_path =
$MYPY_CONFIG_FILE_DIR/foo_dir:$MYPY_CONFIG_FILE_DIR/bar_dir
, $MYPY_CONFIG_FILE_DIR/baz_dir
[file foo_dir/foo.pyi]
def foo(x: int) -> str: ...
[file bar_dir/bar.pyi]
def bar(x: str) -> list: ...
[file baz_dir/baz.pyi]
def baz(x: list) -> dict: ...

[case testDisallowAnyGenericsBuiltinCollections]
# flags: --config-file tmp/mypy.ini
import m
[file mypy.ini]
\[mypy]
\[mypy-m]
disallow_any_generics = True
[file m.py]
def j(s: set) -> None: pass # E: Missing type arguments for generic type "set"
[builtins fixtures/set.pyi]

[case testDisallowAnyGenericsTypingCollections]
# flags: --config-file tmp/mypy.ini
import m
[file mypy.ini]
\[mypy]
\[mypy-m]
disallow_any_generics = True
[file m.py]
from typing import Set
def j(s: Set) -> None: pass # E: Missing type arguments for generic type "Set"
[builtins fixtures/set.pyi]

[case testSectionInheritance]
# flags: --config-file tmp/mypy.ini
import a, a.foo, a.b.c, a.b.c.d.e
[file a/__init__.py]
0()
[file a/foo.py]
0()
[file a/b/__init__.py]
[file a/b/c/__init__.py]
0()
[file a/b/c/d/__init__.py]
[file a/b/c/d/e/__init__.py]
from typing import List
def g(x: List) -> None: pass # E: Missing type arguments for generic type "List"
g(None) # E: Argument 1 to "g" has incompatible type "None"; expected "list[Any]"
[file mypy.ini]
\[mypy]
allow_any_generics = True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if strict optional should also be disabled here, since there is a strict_optional = True below, and when this test was added, it's possible that strict optional was disabled by default.

\[mypy-a.*]
ignore_errors = True
\[mypy-a.b.*]
disallow_any_generics = True
ignore_errors = True
\[mypy-a.b.c.*]
ignore_errors = True
\[mypy-a.b.c.d.*]
ignore_errors = True
\[mypy-a.b.c.d.e.*]
ignore_errors = True
strict_optional = True
\[mypy-a.b.c.d.e]
ignore_errors = False

[case testFollowImportStubs1]
# flags: --config-file tmp/mypy.ini
import math # E: Import of "math" ignored \
# N: (Using --follow-imports=error, module not passed on command line)
math.frobnicate()
[file mypy.ini]
\[mypy]
\[mypy-math.*]
follow_imports = error
follow_imports_for_stubs = True

[case testFollowImportStubs2]
# flags: --config-file tmp/mypy.ini
import math
math.frobnicate()
[file mypy.ini]
\[mypy]
\[mypy-math.*]
follow_imports = skip
follow_imports_for_stubs = True

[case testConfigUnstructuredGlob]
# flags: --config-file tmp/mypy.ini
import emarg.foo, emarg.villip, emarg.hatch.villip.nus, emarg.hatch.villip.mankangulisk, foo.lol
[file mypy.ini]
\[mypy]
ignore_errors = true
\[mypy-*.lol]
ignore_errors = false
\[mypy-emarg.*]
ignore_errors = false
\[mypy-emarg.*.villip.*]
ignore_errors = true
\[mypy-emarg.hatch.villip.mankangulisk]
ignore_errors = false
[file emarg/__init__.py]
[file emarg/foo.py]
fail # E: Name "fail" is not defined
[file emarg/villip.py]
fail
[file emarg/hatch/__init__.py]
[file emarg/hatch/villip/__init__.py]
[file emarg/hatch/villip/nus.py]
fail
[file emarg/hatch/villip/mankangulisk.py]
fail # E: Name "fail" is not defined
[file foo/__init__.py]
[file foo/lol.py]
fail # E: Name "fail" is not defined

[case testIgnoreMissingImportsFalse]
from mod import x
[out]
Expand Down
Loading