8000 Allow disabling active config files. (#6664) · python/mypy@75d4686 · GitHub
[go: up one dir, main page]

Skip to content

Commit 75d4686

Browse files
brandtbucherilevkivskyi
authored andcommitted
Allow disabling active config files. (#6664)
With this change, passing `--config-file=` from the command line disables any active config files.
1 parent 610c125 commit 75d4686

File tree

3 files changed

+14
-1
lines changed
  • docs/source
  • mypy
  • test-data/unit
    • < 8000 div class="PRIVATE_VisuallyHidden prc-TreeView-TreeViewVisuallyHidden-4-mPv" aria-hidden="true" id=":R2rtddabH1:">
      cmdline.test

3 files changed

+14
-1
lines changed

docs/source/command_line.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ Config file
5757
Settings override mypy's built-in defaults and command line flags
5858
can override settings.
5959

60+
Specifying ``--config-file=`` (with no filename) will ignore *all*
61+
config files.
62+
6063
See :ref:`config-file` for the syntax of configuration files.
6164

6265
``--warn-unused-configs``

mypy/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,9 @@ def add_invertible_flag(flag: str,
700700
dummy = argparse.Namespace()
701701
parser.parse_args(args, dummy)
702702
config_file = dummy.config_file
703-
if config_file is not None and not os.path.exists(config_file):
703+
# Don't explicitly test if "config_file is not None" for this check.
704+
# This lets `--config-file=` (an empty string) be used to disable all config files.
705+
if config_file and not os.path.exists(config_file):
704706
parser.error("Cannot find config file '%s'" % config_file)
705707

706708
# Parse config file first, so command line can override.

test-data/unit/cmdline.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ def f():
156156
except ZeroDivisionError, err:
157157
print err
158158

159+
[case testNoConfigFile]
160+
# cmd: mypy main.py --config-file=
161+
[file mypy.ini]
162+
[[mypy]
163+
warn_unused_ignores = True
164+
[file main.py]
165+
# type: ignore
166+
159167
[case testPerFileConfigSection]
160168
# cmd: mypy x.py y.py z.py
161169
[file mypy.ini]

0 commit comments

Comments
 (0)
0