Skip to content

stubtest: Add a --ignore-keyword-only argument #16861

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions docs/source/stubtest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ The rest of this section documents the command line interface of stubtest.

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

.. option:: --ignore-keyword-only

Ignore errors for whether an argument should or shouldn't be keyword-only

.. option:: --allowlist FILE

Use file as an allowlist. Can be passed multiple times to combine multiple
Expand Down
12 changes: 12 additions & 0 deletions mypy/stubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ def is_positional_only_related(self) -> bool:
# TODO: This is hacky, use error codes or something more resilient
return "leading double underscore" in self.message

def is_keyword_only_related(self) -> bool:
"""Whether or not the error is for something being (or not being) keyword-only."""
return "is not keyword-only" in self.message

def get_description(self, concise: bool = False) -> str:
"""Returns a description of the error.

Expand Down Expand Up @@ -1864,6 +1868,7 @@ class _Arguments:
concise: bool
ignore_missing_stub: bool
ignore_positional_only: bool
ignore_keyword_only: bool
allowlist: list[str]
generate_allowlist: bool
ignore_unused_allowlist: bool
Expand Down Expand Up @@ -1940,6 +1945,8 @@ def set_strict_flags() -> None: # not needed yet
continue
if args.ignore_positional_only and error.is_positional_only_related():
continue
if args.ignore_keyword_only and error.is_keyword_only_related():
continue
if error.object_desc in allowlist:
allowlist[error.object_desc] = True
continue
Expand Down Expand Up @@ -2017,6 +2024,11 @@ def parse_options(args: list[str]) -> _Arguments:
action="store_true",
help="Ignore errors for whether an argument should or shouldn't be positional-only",
)
parser.add_argument(
"--ignore-keyword-only",
action="store_true",
help="Ignore errors for whether an argument should or shouldn't be keyword-only",
)
parser.add_argument(
"--allowlist",
"--whitelist",
Expand Down
5 changes: 5 additions & 0 deletions mypy/test/teststubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2263,6 +2263,11 @@ def test_ignore_flags(self) -> None:
)
assert output == "Success: no issues found in 1 module\n"

output = run_stubtest(
stub="def f(*, a): ...", runtime="def f(a): pass", options=["--ignore-keyword-only"]
)
assert output == "Success: no issues found in 1 module\n"

def test_allowlist(self) -> None:
# Can't use this as a context because Windows
allowlist = tempfile.NamedTemporaryFile(mode="w+", delete=False)
Expand Down