Skip to content

Commit 5e5baff

Browse files
committed
[stubgenc] Don't render overloaded function umbrella (*args, **kwargs) signature
Overloaded function header in pybind11 was erroneously recognized as an extra overload.
1 parent 10a0505 commit 5e5baff

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

mypy/stubgenc.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ def is_c_type(obj: object) -> bool:
129129
return inspect.isclass(obj) or type(obj) is type(int)
130130

131131

132+
def is_pybind11_overloaded_function_docstring(docstr: str, name: str) -> bool:
133+
return docstr.startswith("{}(*args, **kwargs)\n".format(name) +
134+
"Overloaded function.\n\n")
135+
136+
132137
def generate_c_function_stub(module: ModuleType,
133138
name: str,
134139
obj: object,
@@ -160,6 +165,9 @@ def generate_c_function_stub(module: ModuleType,
160165
else:
161166
docstr = getattr(obj, '__doc__', None)
162167
inferred = infer_sig_from_docstring(docstr, name)
168+
if inferred and is_pybind11_overloaded_function_docstring(docstr, name):
169+
# Remove pybind11 umbrella (*args, **kwargs) for overloaded functions
170+
del inferred[-1]
163171
if not inferred:
164172
if class_name and name not in sigs:
165173
inferred = [FunctionSig(name, args=infer_method_sig(name), ret_type=ret_type)]

test-data/stubgen/pybind11_mypy_demo/basics.pyi

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,9 @@ class Point:
4848
@overload
4949
def __init__(self, x: float, y: float) -> None: ...
5050
@overload
51-
def __init__(*args, **kwargs) -> Any: ...
52-
@overload
5351
def distance_to(self, x: float, y: float) -> float: ...
5452
@overload
5553
def distance_to(self, other: Point) -> float: ...
56-
@overload
57-
def distance_to(*args, **kwargs) -> Any: ...
5854
@property
5955
def angle_unit(self) -> Point.AngleUnit: ...
6056
@angle_unit.setter

0 commit comments

Comments
 (0)