Skip to content

Commit

Permalink
Make disallow-any-unimported flag invertible (#18030)
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
soceanainn authored Oct 25, 2024
1 parent 715b768 commit 52faccc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 6 additions & 6 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,12 +645,6 @@ def add_invertible_flag(
title="Disallow dynamic typing",
description="Disallow the use of the dynamic 'Any' type under certain conditions.",
)
disallow_any_group.add_argument(
"--disallow-any-unimported",
default=False,
action="store_true",
help="Disallow Any types resulting from unfollowed imports",
)
disallow_any_group.add_argument(
"--disallow-any-expr",
default=False,
Expand All @@ -677,6 +671,12 @@ def add_invertible_flag(
help="Disallow usage of generic types that do not specify explicit type parameters",
group=disallow_any_group,
)
add_invertible_flag(
"--disallow-any-unimported",
default=False,
help="Disallow Any types resulting from unfollowed imports",
group=disallow_any_group,
)
add_invertible_flag(
"--disallow-subclassing-any",
default=False,
Expand Down
6 changes: 6 additions & 0 deletions test-data/unit/check-flags.test
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,12 @@ from missing import Unchecked

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

[case testAllowImplicitAnyVariableDefinition]
# flags: --ignore-missing-imports --allow-any-unimported
from missing import Unchecked

t: Unchecked = 12

[case testDisallowImplicitAnyGeneric]
# flags: --ignore-missing-imports --disallow-any-unimported
from missing import Unchecked
Expand Down

0 comments on commit 52faccc

Please sign in to comment.