@@ -631,6 +631,177 @@ bla bla
631631[file error.py]
632632bla bla
633633
634+ [case testFlagsFile]
635+ # flags: @tmp/flagsfile
636+ x: int
637+ FLAG = False
638+ if not FLAG:
639+ x = "unreachable"
640+ [file flagsfile]
641+ ----always-true=FLAG
642+
643+ [case testConfigFile]
644+ # flags: --config-file tmp/mypy.ini
645+ x: int
646+ FLAG = False
647+ if not FLAG:
648+ x = "unreachable"
649+ [file mypy.ini]
650+ \[mypy]
651+ always_true = FLAG
652+
653+ [case testAltConfigFile]
654+ # flags: --config-file tmp/config.ini
655+ x: int
656+ FLAG = False
657+ if not FLAG:
658+ x = "unreachable"
659+ [file config.ini]
660+ \[mypy]
661+ always_true = FLAG
662+
663+ [case testMultipleGlobConfigSection]
664+ # flags: --config-file tmp/mypy.ini
665+ import x, y, z
666+ [file mypy.ini]
667+ \[mypy]
668+ \[mypy-x.*,z.*]
669+ disallow_untyped_defs = True
670+ [file x.py]
671+ def f(a): pass # E: Function is missing a type annotation
672+ [file y.py]
673+ def f(a): pass
674+ [file z.py]
675+ def f(a): pass # E: Function is missing a type annotation
676+
677+ [case testConfigMypyPath]
678+ # flags: --config-file tmp/mypy.ini
679+ import no_stubs # E: Cannot find implementation or library stub for module named "no_stubs" \
680+ # N: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
681+ from foo import foo
682+ from bar import bar
683+ from baz import baz
684+ baz(bar(foo(42)))
685+ baz(bar(foo('oof'))) # E: Argument 1 to "foo" has incompatible type "str"; expected "int"
686+ [file mypy.ini]
687+ \[mypy]
688+ mypy_path =
689+ $MYPY_CONFIG_FILE_DIR/foo_dir:$MYPY_CONFIG_FILE_DIR/bar_dir
690+ , $MYPY_CONFIG_FILE_DIR/baz_dir
691+ [file foo_dir/foo.pyi]
692+ def foo(x: int) -> str: ...
693+ [file bar_dir/bar.pyi]
694+ def bar(x: str) -> list: ...
695+ [file baz_dir/baz.pyi]
696+ def baz(x: list) -> dict: ...
697+
698+ [case testDisallowAnyGenericsBuiltinCollections]
699+ # flags: --config-file tmp/mypy.ini
700+ import m
701+ [file mypy.ini]
702+ \[mypy]
703+ \[mypy-m]
704+ disallow_any_generics = True
705+ [file m.py]
706+ def j(s: set) -> None: pass # E: Missing type arguments for generic type "set"
707+ [builtins fixtures/set.pyi]
708+
709+ [case testDisallowAnyGenericsTypingCollections]
710+ # flags: --config-file tmp/mypy.ini
711+ import m
712+ [file mypy.ini]
713+ \[mypy]
714+ \[mypy-m]
715+ disallow_any_generics = True
716+ [file m.py]
717+ from typing import Set
718+ def j(s: Set) -> None: pass # E: Missing type arguments for generic type "Set"
719+ [builtins fixtures/set.pyi]
720+
721+ [case testSectionInheritance]
722+ # flags: --config-file tmp/mypy.ini
723+ import a, a.foo, a.b.c, a.b.c.d.e
724+ [file a/__init__.py]
725+ 0()
726+ [file a/foo.py]
727+ 0()
728+ [file a/b/__init__.py]
729+ [file a/b/c/__init__.py]
730+ 0()
731+ [file a/b/c/d/__init__.py]
732+ [file a/b/c/d/e/__init__.py]
733+ from typing import List
734+ def g(x: List) -> None: pass # E: Missing type arguments for generic type "List"
735+ g(None) # E: Argument 1 to "g" has incompatible type "None"; expected "list[Any]"
736+ [file mypy.ini]
737+ \[mypy]
738+ allow_any_generics = True
739+ strict_optional = False
740+ \[mypy-a.*]
741+ ignore_errors = True
742+ \[mypy-a.b.*]
743+ disallow_any_generics = True
744+ ignore_errors = True
745+ \[mypy-a.b.c.*]
746+ ignore_errors = True
747+ \[mypy-a.b.c.d.*]
748+ ignore_errors = True
749+ \[mypy-a.b.c.d.e.*]
750+ ignore_errors = True
751+ strict_optional = True
752+ \[mypy-a.b.c.d.e]
753+ ignore_errors = False
754+
755+ [case testFollowImportStubs1]
756+ # flags: --config-file tmp/mypy.ini
757+ import math # E: Import of "math" ignored \
758+ # N: (Using --follow-imports=error, module not passed on command line)
759+ math.frobnicate()
760+ [file mypy.ini]
761+ \[mypy]
762+ \[mypy-math.*]
763+ follow_imports = error
764+ follow_imports_for_stubs = True
765+
766+ [case testFollowImportStubs2]
767+ # flags: --config-file tmp/mypy.ini
768+ import math
769+ math.frobnicate()
770+ [file mypy.ini]
771+ \[mypy]
772+ \[mypy-math.*]
773+ follow_imports = skip
774+ follow_imports_for_stubs = True
775+
776+ [case testConfigUnstructuredGlob]
777+ # flags: --config-file tmp/mypy.ini
778+ import emarg.foo, emarg.villip, emarg.hatch.villip.nus, emarg.hatch.villip.mankangulisk, foo.lol
779+ [file mypy.ini]
780+ \[mypy]
781+ ignore_errors = true
782+ \[mypy-*.lol]
783+ ignore_errors = false
784+ \[mypy-emarg.*]
785+ ignore_errors = false
786+ \[mypy-emarg.*.villip.*]
787+ ignore_errors = true
788+ \[mypy-emarg.hatch.villip.mankangulisk]
789+ ignore_errors = false
790+ [file emarg/__init__.py]
791+ [file emarg/foo.py]
792+ fail # E: Name "fail" is not defined
793+ [file emarg/villip.py]
794+ fail
795+ [file emarg/hatch/__init__.py]
796+ [file emarg/hatch/villip/__init__.py]
797+ [file emarg/hatch/villip/nus.py]
798+ fail
799+ [file emarg/hatch/villip/mankangulisk.py]
800+ fail # E: Name "fail" is not defined
801+ [file foo/__init__.py]
802+ [file foo/lol.py]
803+ fail # E: Name "fail" is not defined
804+
634805[case testIgnoreMissingImportsFalse]
635806from mod import x
636807[out]
0 commit comments