Skip to content

Commit 6312406

Browse files
author
hauntsaninja
committed
stubtest: add --ignore-unused-whitelist
1 parent 4eff114 commit 6312406

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

mypy/stubtest.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,12 +1071,13 @@ def test_stubs(args: argparse.Namespace) -> int:
10711071
print(error.get_description(concise=args.concise))
10721072

10731073
# Print unused whitelist entries
1074-
for w in whitelist:
1075-
# Don't consider an entry unused if it regex-matches the empty string
1076-
# This allows us to whitelist errors that don't manifest at all on some systems
1077-
if not whitelist[w] and not whitelist_regexes[w].fullmatch(""):
1078-
exit_code = 1
1079-
print("note: unused whitelist entry {}".format(w))
1074+
if not args.ignore_unused_whitelist:
1075+
for w in whitelist:
1076+
# Don't consider an entry unused if it regex-matches the empty string
1077+
# This allows us to whitelist errors that don't manifest at all on some systems
1078+
if not whitelist[w] and not whitelist_regexes[w].fullmatch(""):
1079+
exit_code = 1
1080+
print("note: unused whitelist entry {}".format(w))
10801081

10811082
# Print the generated whitelist
10821083
if args.generate_whitelist:
@@ -1124,6 +1125,12 @@ def parse_options(args: List[str]) -> argparse.Namespace:
11241125
action="store_true",
11251126
help="Print a whitelist (to stdout) to be used with --whitelist",
11261127
)
1128+
parser.add_argument(
1129+
"--ignore-unused-whitelist",
1130+
action="store_true",
1131+
help="Ignore unused whitelist entries",
1132+
)
1133+
11271134
return parser.parse_args(args)
11281135

11291136

mypy/test/teststubtest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,13 @@ def test_whitelist(self) -> None:
631631
output = run_stubtest(stub="", runtime="", options=["--whitelist", whitelist.name])
632632
assert output == "note: unused whitelist entry {}.bad\n".format(TEST_MODULE_NAME)
633633

634+
output = run_stubtest(
635+
stub="",
636+
runtime="",
637+
options=["--whitelist", whitelist.name, "--ignore-unused-whitelist"],
638+
)
639+
assert not output
640+
634641
# test regex matching
635642
with open(whitelist.name, mode="w+") as f:
636643
f.write("{}.b.*\n".format(TEST_MODULE_NAME))

0 commit comments

Comments
 (0)