Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow disabling active config files. #6664

Merged
merged 3 commits into from
Apr 12, 2019
Merged
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
3 changes: 3 additions & 0 deletions docs/source/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ Config file
Settings override mypy's built-in defaults and command line flags
can override settings.

Specifying ``--config-file=`` (with no filename) will ignore *all*
config files.

See :ref:`config-file` for the syntax of configuration files.

``--warn-unused-configs``
Expand Down
4 changes: 3 additions & 1 deletion mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,9 @@ def add_invertible_flag(flag: str,
dummy = argparse.Namespace()
parser.parse_args(args, dummy)
config_file = dummy.config_file
if config_file is not None and not os.path.exists(config_file):
# Don't explicitly test if "config_file is not None" for this check.
# This lets `--config-file=` (an empty string) be used to disable all config files.
if config_file and not os.path.exists(config_file):
parser.error("Cannot find config file '%s'" % config_file)

# Parse config file first, so command line can override.
Expand Down
8 changes: 8 additions & 0 deletions test-data/unit/cmdline.test
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ def f():
except ZeroDivisionError, err:
print err

[case testNoConfigFile]
# cmd: mypy main.py --config-file=
[file mypy.ini]
[[mypy]
warn_unused_ignores = True
[file main.py]
# type: ignore

[case testPerFileConfigSection]
# cmd: mypy x.py y.py z.py
[file mypy.ini]
Expand Down