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
13 changes: 13 additions & 0 deletions mypy/stubdoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,19 @@ def add_token(self, token: tokenize.TokenInfo) -> None:
self.accumulator = ""
self.state.append(STATE_ARGUMENT_TYPE)

elif (
token.type == tokenize.OP
and token.string == ":"
and self.state[-1] == STATE_ARGUMENT_TYPE
and self.accumulator == ""
):
# We thought we were after the colon of an "arg_name: arg_type"
# stanza, so we were expecting an "arg_type" now. However, we ended
# up with "arg_name::" (with two colons). That's a C++ type name,
# not an argument name followed by a Python type. This function
# signature is malformed / invalid.
self.reset()

elif (
token.type == tokenize.OP
and token.string == "="
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/teststubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ def test_infer_sig_from_docstring(self) -> None:
[FunctionSig(name="func", args=[ArgSig(name="x", type=None)], ret_type="Any")],
)

assert_equal(infer_sig_from_docstring("\nfunc(invalid::type)", "func"), [])

assert_equal(
infer_sig_from_docstring('\nfunc(x: str="")', "func"),
[
Expand Down