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
7 changes: 7 additions & 0 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ def main(
options,
)

if options.allow_redefinition_new and options.allow_redefinition_old:
fail(
"--allow-redefinition-old and --allow-redefinition-new should not be used together",
stderr,
options,
)

if options.install_types and (stdout is not sys.stdout or stderr is not sys.stderr):
# Since --install-types performs user input, we want regular stdout and stderr.
fail("error: --install-types not supported in this mode of running mypy", stderr, options)
Expand Down
11 changes: 11 additions & 0 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,17 @@ def refresh_top_level(self, file_node: MypyFile) -> None:
n.end_line = 1
n.end_column = 0
self.fail("--local-partial-types must be enabled if using --allow-redefinition-new", n)
if self.options.allow_redefinition_new and self.options.allow_redefinition_old:
n = TempNode(AnyType(TypeOfAny.special_form))
n.line = 1
n.column = 0
n.end_line = 1
n.end_column = 0
self.fail(
"--allow-redefinition-old and --allow-redefinition-new"
" should not be used together",
n,
)
self.recurse_into_functions = False
self.add_implicit_module_attrs(file_node)
for d in file_node.defs:
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 @@ -2737,3 +2737,9 @@ def f() -> None:
[file mypy.ini]
\[mypy]
disallow_redefinition = true

[case testOnlyOneRedefinitionModeAllowed]
# flags: --allow-redefinition --allow-redefinition-new --local-partial-types
x = 1
[out]
main:1: error: --allow-redefinition-old and --allow-redefinition-new should not be used together