Skip to content

Commit 52faccc

Browse files
authored
Make disallow-any-unimported flag invertible (#18030)
The `--follow-imports=skip` CLI option is pretty much unusable in a project where `disallow_any_unimported` is set to true in the configuration file, as this results in a large number of errors (due to both flags being incompatible). We have a pretty standard project configuration file (with `disallow_any_unimported = true` and `follow_imports = 'normal'`), but for specific local development cases where we want to run the mypy CLI with `--follow-imports=skip` it's incredibly noisy due to the number of errors produced. This change proposes making the `disallow-any-unimported` invertible, so that the CLI can be used with `--follow-imports=skip` in a less noisy way by using: ```bash mypy --follow-imports=skip --allow-any-unimported path/to/my/file.py ```
1 parent 715b768 commit 52faccc

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

mypy/main.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -645,12 +645,6 @@ def add_invertible_flag(
645645
title="Disallow dynamic typing",
646646
description="Disallow the use of the dynamic 'Any' type under certain conditions.",
647647
)
648-
disallow_any_group.add_argument(
649-
"--disallow-any-unimported",
650-
default=False,
651-
action="store_true",
652-
help="Disallow Any types resulting from unfollowed imports",
653-
)
654648
disallow_any_group.add_argument(
655649
"--disallow-any-expr",
656650
default=False,
@@ -677,6 +671,12 @@ def add_invertible_flag(
677671
help="Disallow usage of generic types that do not specify explicit type parameters",
678672
group=disallow_any_group,
679673
)
674+
add_invertible_flag(
675+
"--disallow-any-unimported",
676+
default=False,
677+
help="Disallow Any types resulting from unfollowed imports",
678+
group=disallow_any_group,
679+
)
680680
add_invertible_flag(
681681
"--disallow-subclassing-any",
682682
default=False,

test-data/unit/check-flags.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,12 @@ from missing import Unchecked
963963

964964
t: Unchecked = 12 # E: Type of variable becomes "Any" due to an unfollowed import
965965

966+
[case testAllowImplicitAnyVariableDefinition]
967+
# flags: --ignore-missing-imports --allow-any-unimported
968+
from missing import Unchecked
969+
970+
t: Unchecked = 12
971+
966972
[case testDisallowImplicitAnyGeneric]
967973
# flags: --ignore-missing-imports --disallow-any-unimported
968974
from missing import Unchecked

0 commit comments

Comments
 (0)