Skip to content

Commit 9d9e60d

Browse files
committed
stubtest: Add a --ignore-positional-only argument
1 parent 3f58c2d commit 9d9e60d

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

docs/source/stubtest.rst

+4
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ The rest of this section documents the command line interface of stubtest.
116116

117117
Ignore errors for whether an argument should or shouldn't be positional-only
118118

119+
.. option:: --ignore-keyword-only
120+
121+
Ignore errors for whether an argument should or shouldn't be keyword-only
122+
119123
.. option:: --allowlist FILE
120124

121125
Use file as an allowlist. Can be passed multiple times to combine multiple

mypy/stubtest.py

+12
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ def is_positional_only_related(self) -> bool:
135135
# TODO: This is hacky, use error codes or something more resilient
136136
return "leading double underscore" in self.message
137137

138+
def is_keyword_only_related(self) -> bool:
139+
"""Whether or not the error is for something being (or not being) keyword-only."""
140+
return "is not keyword-only" in self.message
141+
138142
def get_description(self, concise: bool = False) -> str:
139143
"""Returns a description of the error.
140144
@@ -1864,6 +1868,7 @@ class _Arguments:
18641868
concise: bool
18651869
ignore_missing_stub: bool
18661870
ignore_positional_only: bool
1871+
ignore_keyword_only: bool
18671872
allowlist: list[str]
18681873
generate_allowlist: bool
18691874
ignore_unused_allowlist: bool
@@ -1940,6 +1945,8 @@ def set_strict_flags() -> None: # not needed yet
19401945
continue
19411946
if args.ignore_positional_only and error.is_positional_only_related():
19421947
continue
1948+
if args.ignore_keyword_only and error.is_keyword_only_related():
1949+
continue
19431950
if error.object_desc in allowlist:
19441951
allowlist[error.object_desc] = True
19451952
continue
@@ -2017,6 +2024,11 @@ def parse_options(args: list[str]) -> _Arguments:
20172024
action="store_true",
20182025
help="Ignore errors for whether an argument should or shouldn't be positional-only",
20192026
)
2027+
parser.add_argument(
2028+
"--ignore-keyword-only",
2029+
action="store_true",
2030+
help="Ignore errors for whether an argument should or shouldn't be keyword-only",
2031+
)
20202032
parser.add_argument(
20212033
"--allowlist",
20222034
"--whitelist",

mypy/test/teststubtest.py

+6
Original file line numberDiff line numberDiff line change
@@ -2263,6 +2263,12 @@ def test_ignore_flags(self) -> None:
22632263
)
22642264
assert output == "Success: no issues found in 1 module\n"
22652265

2266+
output = run_stubtest(
2267+
stub="def f(*, a): ...", runtime="def f(a): pass", options=["--ignore-keyword-only"],
2268+
)
2269+
assert output == "Success: no issues found in 1 module\n"
2270+
2271+
22662272
def test_allowlist(self) -> None:
22672273
# Can't use this as a context because Windows
22682274
allowlist = tempfile.NamedTemporaryFile(mode="w+", delete=False)

0 commit comments

Comments
 (0)