Skip to content
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
5 changes: 4 additions & 1 deletion mypy/stubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,10 @@ def _get_func_args(self, o: FuncDef, ctx: FunctionContext) -> list[ArgSig]:
if not isinstance(get_proper_type(annotated_type), AnyType):
typename = self.print_annotation(annotated_type)

if actually_pos_only_args and arg_.pos_only:
# A keyword-only argument is never positional-only, even when its name
# starts with two underscores, so it must not move the "/" marker past
# the "*" separator.
if actually_pos_only_args and arg_.pos_only and not kind.is_named():
pos_only_marker_position += 1

if kind.is_named() and not any(arg.name.startswith("*") for arg in args):
Expand Down
12 changes: 12 additions & 0 deletions test-data/unit/stubgen.test
Original file line number Diff line number Diff line change
Expand Up @@ -4566,6 +4566,18 @@ def f6(x: int = 0, /, *, y: float): ...
def f7(x: int, /, *, y: float = 1): ...
def f8(x: int = 0, /, *, y: float = 1): ...

[case testHistoricalPosOnlyParamsWithKeywordOnly]
def f1(*, __kw): ...
def f2(x, /, *, __kw): ...
def f3(__pos, *, kw): ...
def f4(__pos, __other, *, __kw): ...

[out]
def f1(*, __kw) -> None: ...
def f2(x, /, *, __kw) -> None: ...
def f3(__pos, /, *, kw) -> None: ...
def f4(__pos, __other, /, *, __kw) -> None: ...

[case testPreserveEmptyTuple]
ann: tuple[()]
alias = tuple[()]
Expand Down
Loading