From a41780b415c20df1693882b8db888a87c6e025af Mon Sep 17 00:00:00 2001 From: Yoshiki Matsuda Date: Fri, 13 Oct 2023 15:06:23 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Accept=20nanobind=20module=20for=20?= =?UTF-8?q?stubgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mypy/stubdoc.py | 15 ++++++++------- mypy/stubgenc.py | 11 ++++++++++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/mypy/stubdoc.py b/mypy/stubdoc.py index 145f57fd77516..55ddc134ae8c1 100644 --- a/mypy/stubdoc.py +++ b/mypy/stubdoc.py @@ -163,13 +163,14 @@ def add_token(self, token: tokenize.TokenInfo) -> None: self.arg_type = self.accumulator self.state.pop() elif self.state[-1] == STATE_ARGUMENT_LIST: - self.arg_name = self.accumulator - if not ( - token.string == ")" and self.accumulator.strip() == "" - ) and not _ARG_NAME_RE.match(self.arg_name): - # Invalid argument name. - self.reset() - return + if not self.accumulator == "/": + self.arg_name = self.accumulator + if not ( + token.string == ")" and self.accumulator.strip() == "" + ) and not _ARG_NAME_RE.match(self.arg_name): + # Invalid argument name. + self.reset() + return if token.string == ")": self.state.pop() diff --git a/mypy/stubgenc.py b/mypy/stubgenc.py index 31487f9d0dcf1..332af7b17838c 100755 --- a/mypy/stubgenc.py +++ b/mypy/stubgenc.py @@ -38,6 +38,7 @@ "Optional", "Tuple", "Union", + "Sequence", ) @@ -194,7 +195,7 @@ def generate_stub_for_c_module( done = set() items = sorted(get_members(module), key=lambda x: x[0]) for name, obj in items: - if is_c_function(obj): + if is_c_function(obj) or is_nanobind_function(obj): generate_c_function_stub( module, name, @@ -307,6 +308,14 @@ def is_c_type(obj: object) -> bool: return inspect.isclass(obj) or type(obj) is type(int) +def is_nanobind_function(obj: object) -> bool: + return ( + hasattr(type(obj), "__module__") + and type(obj).__module__ == "nanobind" + and type(obj).__name__ == "nb_func" + ) + + def is_pybind11_overloaded_function_docstring(docstr: str, name: str) -> bool: return docstr.startswith(f"{name}(*args, **kwargs)\n" + "Overloaded function.\n\n")