Skip to content
Merged
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
2 changes: 1 addition & 1 deletion mypy/stubdoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def infer_sig_from_docstring(docstr: str | None, name: str) -> list[FunctionSig]
* docstr: docstring
* name: name of function for which signatures are to be found
"""
if not docstr:
if not (isinstance(docstr, str) and docstr):
return None

state = DocStringParser(name)
Expand Down
21 changes: 21 additions & 0 deletions mypy/test/teststubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,27 @@ def test(arg0: str) -> None:
assert_equal(output, ["def test(arg0: foo.bar.Action) -> other.Thing: ..."])
assert_equal(set(imports), {"import foo", "import other"})

def test_generate_c_function_no_crash_for_non_str_docstring(self) -> None:
def test(arg0: str) -> None:
...

test.__doc__ = property(lambda self: "test(arg0: str) -> None") # type: ignore[assignment]

output: list[str] = []
imports: list[str] = []
mod = ModuleType(self.__module__, "")
generate_c_function_stub(
mod,
"test",
test,
output=output,
imports=imports,
known_modules=[mod.__name__],
sig_generators=get_sig_generators(parse_options([])),
)
assert_equal(output, ["def test(*args, **kwargs) -> Any: ..."])
assert_equal(imports, [])

def test_generate_c_property_with_pybind11(self) -> None:
"""Signatures included by PyBind11 inside property.fget are read."""

Expand Down