From 5dab1e9e4eddf42d75e55790b1a0c65491255612 Mon Sep 17 00:00:00 2001 From: gentlegiantJGC Date: Thu, 18 Sep 2025 09:37:08 +0100 Subject: [PATCH] Remove leading newlines from docstrings If pybind11-stubgen is run on a normal python docstring it will convert this ```py """ This is a docstring. """ ``` To this ```py """ This is a docstring. """ ``` The leading newline is interpreted as part of the docstring and pybind11-stubgen will add another newline as part of its formatting. Stripping these leading newlines should have no effect in docstrings defined using pybind11 unless the user adds a leading newline for some reason. --- pybind11_stubgen/printer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pybind11_stubgen/printer.py b/pybind11_stubgen/printer.py index 8ef4af20..5412ba91 100644 --- a/pybind11_stubgen/printer.py +++ b/pybind11_stubgen/printer.py @@ -124,7 +124,7 @@ def print_docstring(self, doc: Docstring) -> list[str]: '"""', *( line.replace("\\", r"\\").replace('"""', r"\"\"\"") - for line in doc.splitlines() + for line in doc.lstrip("\n").splitlines() ), '"""', ]