Skip to content

Commit 6653fbd

Browse files
committed
update kwarg only
1 parent a6d1749 commit 6653fbd

File tree

2 files changed

+8
-12
lines changed
  • mypy
  • test-data/pybind11_fixtures/expected_stubs_with_docs/pybind11_fixtures

2 files changed

+8
-12
lines changed

mypy/stubdoc.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ def format_sig(
144144
if self.pos_only_index:
145145
args.insert(self.pos_only_index, '/')
146146
if self.kwarg_only_index:
147-
pos_offset = 1 if self.pos_only_index else 0
148-
args.insert(self.kwarg_only_index + pos_offset, '*')
147+
args.insert(self.kwarg_only_index, '*')
149148

150149
retfield = ""
151150
ret_type = self.ret_type if self.ret_type else any_val
@@ -190,6 +189,7 @@ def __init__(self, function_name: str) -> None:
190189
self.args: list[ArgSig] = []
191190
self.pos_only: int | None = None
192191
self.keyword_only: int | None = None
192+
self.keyword_only_index: int | None = None
193193
# Valid signatures found so far.
194194
self.signatures: list[FunctionSig] = []
195195

@@ -273,6 +273,7 @@ def add_token(self, token: tokenize.TokenInfo) -> None:
273273
self.reset()
274274
return
275275
self.keyword_only = len(self.args)
276+
self.keyword_only_index = self.keyword_only
276277
self.accumulator = ""
277278
else:
278279
if self.accumulator.startswith("*"):
@@ -350,7 +351,7 @@ def add_token(self, token: tokenize.TokenInfo) -> None:
350351

351352
if self.found:
352353
self.signatures.append(
353-
FunctionSig(name=self.function_name, args=self.args, pos_only_index=self.pos_only, kwarg_only_index=self.keyword_only, ret_type=self.ret_type)
354+
FunctionSig(name=self.function_name, args=self.args, pos_only_index=self.pos_only, kwarg_only_index=self.keyword_only_index, ret_type=self.ret_type)
354355
)
355356
self.found = False
356357
self.args = []

test-data/pybind11_fixtures/expected_stubs_with_docs/pybind11_fixtures/demo.pyi

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ class Point:
2828
"""__ne__(self: object, other: object) -> bool"""
2929
@property
3030
def name(self) -> str:
31-
"""name(self: handle) -> str
31+
"""name(self: object) -> str
3232
33-
name(self: handle) -> str
33+
name(self: object) -> str
3434
"""
3535
@property
3636
def value(self) -> int:
@@ -63,9 +63,9 @@ class Point:
6363
"""__ne__(self: object, other: object) -> bool"""
6464
@property
6565
def name(self) -> str:
66-
"""name(self: handle) -> str
66+
"""name(self: object) -> str
6767
68-
name(self: handle) -> str
68+
name(self: object) -> str
6969
"""
7070
@property
7171
def value(self) -> int:
@@ -126,19 +126,14 @@ def answer() -> int:
126126
'''
127127
def midpoint(left: float, right: float) -> float:
128128
"""midpoint(left: float, right: float) -> float"""
129-
130129
def pos_kw_only_mix(i: int, /, j: int, *, k: int) -> tuple:
131130
"""pos_kw_only_mix(i: int, /, j: int, *, k: int) -> tuple"""
132-
133131
def pos_only_all(i: int, j: int, /) -> tuple:
134132
"""pos_only_all(i: int, j: int, /) -> tuple"""
135-
136133
def pos_only_def_mix(i: int, j: int = ..., /, k: int = ...) -> tuple:
137134
"""pos_only_def_mix(i: int, j: int = 2, /, k: int = 3) -> tuple"""
138-
139135
def pos_only_mix(i: int, /, j: int) -> tuple:
140136
"""pos_only_mix(i: int, /, j: int) -> tuple"""
141-
142137
def sum(arg0: int, arg1: int) -> int:
143138
'''sum(arg0: int, arg1: int) -> int
144139

0 commit comments

Comments
 (0)