Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

stubtest: fix pos-only handling in overload resolution#16750

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
JelleZijlstra merged 2 commits intopython:masterfromhauntsaninja:fix-stubtest
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes fromall 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
7 changes: 6 additions & 1 deletionmypy/stubtest.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -828,7 +828,10 @@ def from_overloadedfuncdef(stub: nodes.OverloadedFuncDef) -> Signature[nodes.Arg
# argument. To accomplish this, we just make up a fake index-based name.
name = (
f"__{index}"
if arg.variable.name.startswith("__") or assume_positional_only
if arg.variable.name.startswith("__")
or arg.pos_only
or assume_positional_only
or arg.variable.name.strip("_") == "self"
else arg.variable.name
)
all_args.setdefault(name, []).append((arg, index))
Expand DownExpand Up@@ -872,6 +875,7 @@ def get_kind(arg_name: str) -> nodes.ArgKind:
type_annotation=None,
initializer=None,
kind=get_kind(arg_name),
pos_only=all(arg.pos_only for arg, _ in all_args[arg_name]),
)
if arg.kind.is_positional():
sig.pos.append(arg)
Expand DownExpand Up@@ -907,6 +911,7 @@ def _verify_signature(
if (
runtime_arg.kind != inspect.Parameter.POSITIONAL_ONLY
and (stub_arg.pos_only or stub_arg.variable.name.startswith("__"))
and stub_arg.variable.name.strip("_") != "self"
and not is_dunder(function_name, exclude_special=True) # noisy for dunder methods
):
yield (
Expand Down
58 changes: 57 additions & 1 deletionmypy/test/teststubtest.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -210,7 +210,13 @@ def test(*args: Any, **kwargs: Any) -> None:
)

actual_errors = set(output.splitlines())
assert actual_errors == expected_errors, output
if actual_errors != expected_errors:
output = run_stubtest(
stub="\n\n".join(textwrap.dedent(c.stub.lstrip("\n")) for c in cases),
runtime="\n\n".join(textwrap.dedent(c.runtime.lstrip("\n")) for c in cases),
options=[],
)
assert actual_errors == expected_errors, output

return test

Expand DownExpand Up@@ -660,6 +666,56 @@ def f6(self, x, /): pass
""",
error=None,
)
yield Case(
stub="""
@overload
def f7(a: int, /) -> int: ...
@overload
def f7(b: str, /) -> str: ...
""",
runtime="def f7(x, /): pass",
error=None,
)
yield Case(
stub="""
@overload
def f8(a: int, c: int = 0, /) -> int: ...
@overload
def f8(b: str, d: int, /) -> str: ...
""",
runtime="def f8(x, y, /): pass",
error="f8",
)
yield Case(
stub="""
@overload
def f9(a: int, c: int = 0, /) -> int: ...
@overload
def f9(b: str, d: int, /) -> str: ...
""",
runtime="def f9(x, y=0, /): pass",
error=None,
)
yield Case(
stub="""
class Bar:
@overload
def f1(self) -> int: ...
Copy link
CollaboratorAuthor

@hauntsaninjahauntsaninjaJan 12, 2024
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We have instances of this inpython/typeshed#11250, I don't think it's worth having stubtest complain that this isn't positional-only, at least for now

@overload
def f1(self, a: int, /) -> int: ...

@overload
def f2(self, a: int, /) -> int: ...
@overload
def f2(self, a: str, /) -> int: ...
""",
runtime="""
class Bar:
def f1(self, *a) -> int: ...
def f2(self, *a) -> int: ...
""",
error=None,
)

@collect_cases
def test_property(self) -> Iterator[Case]:
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp