diff --git a/mypy/stubdoc.py b/mypy/stubdoc.py index 89db6cb3378f..8f984037f96c 100644 --- a/mypy/stubdoc.py +++ b/mypy/stubdoc.py @@ -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 == "=" diff --git a/mypy/test/teststubgen.py b/mypy/test/teststubgen.py index 43974cf8ec68..605409f99523 100644 --- a/mypy/test/teststubgen.py +++ b/mypy/test/teststubgen.py @@ -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"), [