From ff885c381d6d4592bdc6db7503cb8be3a89f7056 Mon Sep 17 00:00:00 2001 From: Fabian Keller Date: Sun, 7 Jan 2024 18:04:58 +0100 Subject: [PATCH 1/3] improve stubgen tests --- misc/test-stubgenc.sh | 13 ++- .../pybind11_mypy_demo/__init__.pyi | 16 +++ .../pybind11_mypy_demo/demo.pyi} | 0 .../pybind11_mypy_demo/__init__.pyi | 22 ++++ .../pybind11_mypy_demo/demo.pyi} | 30 ++--- test-data/pybind11_mypy_demo/src/main.cpp | 107 +++++++++++++++--- .../pybind11_mypy_demo/__init__.pyi | 1 - .../stubgen/pybind11_mypy_demo/__init__.pyi | 1 - 8 files changed, 158 insertions(+), 32 deletions(-) create mode 100644 test-data/pybind11_mypy_demo/expected_stubs_no_docs/pybind11_mypy_demo/__init__.pyi rename test-data/pybind11_mypy_demo/{stubgen/pybind11_mypy_demo/basics.pyi => expected_stubs_no_docs/pybind11_mypy_demo/demo.pyi} (100%) create mode 100644 test-data/pybind11_mypy_demo/expected_stubs_with_docs/pybind11_mypy_demo/__init__.pyi rename test-data/pybind11_mypy_demo/{stubgen-include-docs/pybind11_mypy_demo/basics.pyi => expected_stubs_with_docs/pybind11_mypy_demo/demo.pyi} (70%) delete mode 100644 test-data/pybind11_mypy_demo/stubgen-include-docs/pybind11_mypy_demo/__init__.pyi delete mode 100644 test-data/pybind11_mypy_demo/stubgen/pybind11_mypy_demo/__init__.pyi diff --git a/misc/test-stubgenc.sh b/misc/test-stubgenc.sh index 5cb5140eba76..c69b9eb14727 100755 --- a/misc/test-stubgenc.sh +++ b/misc/test-stubgenc.sh @@ -21,15 +21,24 @@ function stubgenc_test() { rm -rf "${STUBGEN_OUTPUT_FOLDER:?}/*" stubgen -o "$STUBGEN_OUTPUT_FOLDER" "${@:2}" + # Check if generated stubs can actually be type checked by mypy + if ! mypy "$STUBGEN_OUTPUT_FOLDER"; + then + echo "Stubgen test failed, because generated stubs failed to type check." + EXIT=1 + fi + # Compare generated stubs to expected ones if ! git diff --exit-code "$STUBGEN_OUTPUT_FOLDER"; then + echo "Stubgen test failed, because generated stubs differ from expected outputs." EXIT=1 fi } # create stubs without docstrings -stubgenc_test stubgen -p pybind11_mypy_demo +stubgenc_test expected_stubs_no_docs -p pybind11_mypy_demo # create stubs with docstrings -stubgenc_test stubgen-include-docs -p pybind11_mypy_demo --include-docstrings +stubgenc_test expected_stubs_with_docs -p pybind11_mypy_demo --include-docstrings + exit $EXIT diff --git a/test-data/pybind11_mypy_demo/expected_stubs_no_docs/pybind11_mypy_demo/__init__.pyi b/test-data/pybind11_mypy_demo/expected_stubs_no_docs/pybind11_mypy_demo/__init__.pyi new file mode 100644 index 000000000000..8c361d40fd02 --- /dev/null +++ b/test-data/pybind11_mypy_demo/expected_stubs_no_docs/pybind11_mypy_demo/__init__.pyi @@ -0,0 +1,16 @@ +import os +from . import demo as demo +from typing import List, Optional, Tuple + +class TestStruct: + field_readwrite: int + field_readwrite_docstring: int + def __init__(self, *args, **kwargs) -> None: ... + @property + def field_readonly(self) -> int: ... + +def func_incomplete_signature(*args, **kwargs): ... +def func_returning_optional() -> Optional[int]: ... +def func_returning_pair() -> Tuple[int, float]: ... +def func_returning_path() -> os.PathLike: ... +def func_returning_vector() -> List[float]: ... diff --git a/test-data/pybind11_mypy_demo/stubgen/pybind11_mypy_demo/basics.pyi b/test-data/pybind11_mypy_demo/expected_stubs_no_docs/pybind11_mypy_demo/demo.pyi similarity index 100% rename from test-data/pybind11_mypy_demo/stubgen/pybind11_mypy_demo/basics.pyi rename to test-data/pybind11_mypy_demo/expected_stubs_no_docs/pybind11_mypy_demo/demo.pyi diff --git a/test-data/pybind11_mypy_demo/expected_stubs_with_docs/pybind11_mypy_demo/__init__.pyi b/test-data/pybind11_mypy_demo/expected_stubs_with_docs/pybind11_mypy_demo/__init__.pyi new file mode 100644 index 000000000000..dacdc1d51ac2 --- /dev/null +++ b/test-data/pybind11_mypy_demo/expected_stubs_with_docs/pybind11_mypy_demo/__init__.pyi @@ -0,0 +1,22 @@ +import os +from . import demo as demo +from typing import List, Optional, Tuple + +class TestStruct: + field_readwrite: int + field_readwrite_docstring: int + def __init__(self, *args, **kwargs) -> None: + """Initialize self. See help(type(self)) for accurate signature.""" + @property + def field_readonly(self) -> int: ... + +def func_incomplete_signature(*args, **kwargs): + """func_incomplete_signature() -> dummy_sub_namespace::HasNoBinding""" +def func_returning_optional() -> Optional[int]: + """func_returning_optional() -> Optional[int]""" +def func_returning_pair() -> Tuple[int, float]: + """func_returning_pair() -> Tuple[int, float]""" +def func_returning_path() -> os.PathLike: + """func_returning_path() -> os.PathLike""" +def func_returning_vector() -> List[float]: + """func_returning_vector() -> List[float]""" diff --git a/test-data/pybind11_mypy_demo/stubgen-include-docs/pybind11_mypy_demo/basics.pyi b/test-data/pybind11_mypy_demo/expected_stubs_with_docs/pybind11_mypy_demo/demo.pyi similarity index 70% rename from test-data/pybind11_mypy_demo/stubgen-include-docs/pybind11_mypy_demo/basics.pyi rename to test-data/pybind11_mypy_demo/expected_stubs_with_docs/pybind11_mypy_demo/demo.pyi index b761291e11f3..c55376eff5c3 100644 --- a/test-data/pybind11_mypy_demo/stubgen-include-docs/pybind11_mypy_demo/basics.pyi +++ b/test-data/pybind11_mypy_demo/expected_stubs_with_docs/pybind11_mypy_demo/demo.pyi @@ -10,15 +10,15 @@ class Point: degree: ClassVar[Point.AngleUnit] = ... radian: ClassVar[Point.AngleUnit] = ... def __init__(self, value: int) -> None: - """__init__(self: pybind11_mypy_demo.basics.Point.AngleUnit, value: int) -> None""" + """__init__(self: pybind11_mypy_demo.demo.Point.AngleUnit, value: int) -> None""" def __eq__(self, other: object) -> bool: """__eq__(self: object, other: object) -> bool""" def __hash__(self) -> int: """__hash__(self: object) -> int""" def __index__(self) -> int: - """__index__(self: pybind11_mypy_demo.basics.Point.AngleUnit) -> int""" + """__index__(self: pybind11_mypy_demo.demo.Point.AngleUnit) -> int""" def __int__(self) -> int: - """__int__(self: pybind11_mypy_demo.basics.Point.AngleUnit) -> int""" + """__int__(self: pybind11_mypy_demo.demo.Point.AngleUnit) -> int""" def __ne__(self, other: object) -> bool: """__ne__(self: object, other: object) -> bool""" @property @@ -33,15 +33,15 @@ class Point: mm: ClassVar[Point.LengthUnit] = ... pixel: ClassVar[Point.LengthUnit] = ... def __init__(self, value: int) -> None: - """__init__(self: pybind11_mypy_demo.basics.Point.LengthUnit, value: int) -> None""" + """__init__(self: pybind11_mypy_demo.demo.Point.LengthUnit, value: int) -> None""" def __eq__(self, other: object) -> bool: """__eq__(self: object, other: object) -> bool""" def __hash__(self) -> int: """__hash__(self: object) -> int""" def __index__(self) -> int: - """__index__(self: pybind11_mypy_demo.basics.Point.LengthUnit) -> int""" + """__index__(self: pybind11_mypy_demo.demo.Point.LengthUnit) -> int""" def __int__(self) -> int: - """__int__(self: pybind11_mypy_demo.basics.Point.LengthUnit) -> int""" + """__int__(self: pybind11_mypy_demo.demo.Point.LengthUnit) -> int""" def __ne__(self, other: object) -> bool: """__ne__(self: object, other: object) -> bool""" @property @@ -60,38 +60,38 @@ class Point: """__init__(*args, **kwargs) Overloaded function. - 1. __init__(self: pybind11_mypy_demo.basics.Point) -> None + 1. __init__(self: pybind11_mypy_demo.demo.Point) -> None - 2. __init__(self: pybind11_mypy_demo.basics.Point, x: float, y: float) -> None + 2. __init__(self: pybind11_mypy_demo.demo.Point, x: float, y: float) -> None """ @overload def __init__(self, x: float, y: float) -> None: """__init__(*args, **kwargs) Overloaded function. - 1. __init__(self: pybind11_mypy_demo.basics.Point) -> None + 1. __init__(self: pybind11_mypy_demo.demo.Point) -> None - 2. __init__(self: pybind11_mypy_demo.basics.Point, x: float, y: float) -> None + 2. __init__(self: pybind11_mypy_demo.demo.Point, x: float, y: float) -> None """ def as_list(self) -> List[float]: - """as_list(self: pybind11_mypy_demo.basics.Point) -> List[float]""" + """as_list(self: pybind11_mypy_demo.demo.Point) -> List[float]""" @overload def distance_to(self, x: float, y: float) -> float: """distance_to(*args, **kwargs) Overloaded function. - 1. distance_to(self: pybind11_mypy_demo.basics.Point, x: float, y: float) -> float + 1. distance_to(self: pybind11_mypy_demo.demo.Point, x: float, y: float) -> float - 2. distance_to(self: pybind11_mypy_demo.basics.Point, other: pybind11_mypy_demo.basics.Point) -> float + 2. distance_to(self: pybind11_mypy_demo.demo.Point, other: pybind11_mypy_demo.demo.Point) -> float """ @overload def distance_to(self, other: Point) -> float: """distance_to(*args, **kwargs) Overloaded function. - 1. distance_to(self: pybind11_mypy_demo.basics.Point, x: float, y: float) -> float + 1. distance_to(self: pybind11_mypy_demo.demo.Point, x: float, y: float) -> float - 2. distance_to(self: pybind11_mypy_demo.basics.Point, other: pybind11_mypy_demo.basics.Point) -> float + 2. distance_to(self: pybind11_mypy_demo.demo.Point, other: pybind11_mypy_demo.demo.Point) -> float """ @property def length(self) -> float: ... diff --git a/test-data/pybind11_mypy_demo/src/main.cpp b/test-data/pybind11_mypy_demo/src/main.cpp index 192a90cf8e30..8074e4b2d9e8 100644 --- a/test-data/pybind11_mypy_demo/src/main.cpp +++ b/test-data/pybind11_mypy_demo/src/main.cpp @@ -43,12 +43,85 @@ */ #include +#include +#include +#include +#include + #include #include +#include namespace py = pybind11; -namespace basics { +// ---------------------------------------------------------------------------- +// Dedicated test cases +// ---------------------------------------------------------------------------- + +std::vector funcReturningVector() +{ + return std::vector{1.0, 2.0, 3.0}; +} + +std::pair funcReturningPair() +{ + return std::pair{42, 1.0}; +} + +std::optional funcReturningOptional() +{ + return std::nullopt; +} + +std::filesystem::path funcReturningPath() +{ + return std::filesystem::path{"foobar"}; +} + +namespace dummy_sub_namespace { + struct HasNoBinding{}; +} + +// We can enforce the case of an incomplete signature by referring to a type in +// some namespace that doesn't have a pybind11 binding. +dummy_sub_namespace::HasNoBinding funcIncompleteSignature() +{ + return dummy_sub_namespace::HasNoBinding{}; +} + +struct TestStruct +{ + int field_readwrite; + int field_readwrite_docstring; + int field_readonly; +}; + +// Bindings + +void bind_test_cases(py::module& m) { + m.def("func_returning_vector", &funcReturningVector); + m.def("func_returning_pair", &funcReturningPair); + m.def("func_returning_optional", &funcReturningOptional); + m.def("func_returning_path", &funcReturningPath); + + m.def("func_incomplete_signature", &funcIncompleteSignature); + + py::class_(m, "TestStruct") + .def_readwrite("field_readwrite", &TestStruct::field_readwrite) + .def_readwrite("field_readwrite_docstring", &TestStruct::field_readwrite_docstring, "some docstring") + .def_property_readonly( + "field_readonly", + [](const TestStruct& x) { + return x.field_readonly; + }, + "some docstring"); +} + +// ---------------------------------------------------------------------------- +// Original demo +// ---------------------------------------------------------------------------- + +namespace demo { int answer() { return 42; @@ -118,20 +191,22 @@ const Point Point::y_axis = Point(0, 1); Point::LengthUnit Point::length_unit = Point::LengthUnit::mm; Point::AngleUnit Point::angle_unit = Point::AngleUnit::radian; -} // namespace: basics +} // namespace: demo -void bind_basics(py::module& basics) { +// Bindings - using namespace basics; +void bind_demo(py::module& m) { + + using namespace demo; // Functions - basics.def("answer", &answer, "answer docstring, with end quote\""); // tests explicit docstrings - basics.def("sum", &sum, "multiline docstring test, edge case quotes \"\"\"'''"); - basics.def("midpoint", &midpoint, py::arg("left"), py::arg("right")); - basics.def("weighted_midpoint", weighted_midpoint, py::arg("left"), py::arg("right"), py::arg("alpha")=0.5); + m.def("answer", &answer, "answer docstring, with end quote\""); // tests explicit docstrings + m.def("sum", &sum, "multiline docstring test, edge case quotes \"\"\"'''"); + m.def("midpoint", &midpoint, py::arg("left"), py::arg("right")); + m.def("weighted_midpoint", weighted_midpoint, py::arg("left"), py::arg("right"), py::arg("alpha")=0.5); // Classes - py::class_ pyPoint(basics, "Point"); + py::class_ pyPoint(m, "Point"); py::enum_ pyLengthUnit(pyPoint, "LengthUnit"); py::enum_ pyAngleUnit(pyPoint, "AngleUnit"); @@ -167,11 +242,17 @@ void bind_basics(py::module& basics) { .value("degree", Point::AngleUnit::degree); // Module-level attributes - basics.attr("PI") = std::acos(-1); - basics.attr("__version__") = "0.0.1"; + m.attr("PI") = std::acos(-1); + m.attr("__version__") = "0.0.1"; } +// ---------------------------------------------------------------------------- +// Module entry point +// ---------------------------------------------------------------------------- + PYBIND11_MODULE(pybind11_mypy_demo, m) { - auto basics = m.def_submodule("basics"); - bind_basics(basics); + bind_test_cases(m); + + auto demo = m.def_submodule("demo"); + bind_demo(demo); } diff --git a/test-data/pybind11_mypy_demo/stubgen-include-docs/pybind11_mypy_demo/__init__.pyi b/test-data/pybind11_mypy_demo/stubgen-include-docs/pybind11_mypy_demo/__init__.pyi deleted file mode 100644 index 0cb252f00259..000000000000 --- a/test-data/pybind11_mypy_demo/stubgen-include-docs/pybind11_mypy_demo/__init__.pyi +++ /dev/null @@ -1 +0,0 @@ -from . import basics as basics diff --git a/test-data/pybind11_mypy_demo/stubgen/pybind11_mypy_demo/__init__.pyi b/test-data/pybind11_mypy_demo/stubgen/pybind11_mypy_demo/__init__.pyi deleted file mode 100644 index 0cb252f00259..000000000000 --- a/test-data/pybind11_mypy_demo/stubgen/pybind11_mypy_demo/__init__.pyi +++ /dev/null @@ -1 +0,0 @@ -from . import basics as basics From ffb13a68f1f03b1da2cbd8f5a06ccd47f06fa651 Mon Sep 17 00:00:00 2001 From: Fabian Keller Date: Sun, 7 Jan 2024 19:28:20 +0100 Subject: [PATCH 2/3] fix broken pre-delete bug in test-stubgenc.sh --- misc/test-stubgenc.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/misc/test-stubgenc.sh b/misc/test-stubgenc.sh index c69b9eb14727..5ef23a72e832 100755 --- a/misc/test-stubgenc.sh +++ b/misc/test-stubgenc.sh @@ -18,7 +18,8 @@ EXIT=0 function stubgenc_test() { # Remove expected stubs and generate new inplace STUBGEN_OUTPUT_FOLDER=./test-data/pybind11_mypy_demo/$1 - rm -rf "${STUBGEN_OUTPUT_FOLDER:?}/*" + rm -rf "${STUBGEN_OUTPUT_FOLDER:?}" + stubgen -o "$STUBGEN_OUTPUT_FOLDER" "${@:2}" # Check if generated stubs can actually be type checked by mypy From 90c767444a414052ade739ca585f9c4ec241f721 Mon Sep 17 00:00:00 2001 From: Fabian Keller Date: Sat, 13 Jan 2024 08:24:38 +0100 Subject: [PATCH 3/3] rename pybind11 test project from 'pybind11_mypy_demo' to 'pybind11_fixtures' --- .github/workflows/test_stubgenc.yml | 2 +- misc/test-stubgenc.sh | 8 ++--- .../pybind11_fixtures}/__init__.pyi | 0 .../pybind11_fixtures}/demo.pyi | 0 .../pybind11_fixtures}/__init__.pyi | 0 .../pybind11_fixtures}/demo.pyi | 30 +++++++++---------- .../pyproject.toml | 0 .../setup.py | 4 +-- .../src/main.cpp | 2 +- 9 files changed, 23 insertions(+), 23 deletions(-) rename test-data/{pybind11_mypy_demo/expected_stubs_no_docs/pybind11_mypy_demo => pybind11_fixtures/expected_stubs_no_docs/pybind11_fixtures}/__init__.pyi (100%) rename test-data/{pybind11_mypy_demo/expected_stubs_no_docs/pybind11_mypy_demo => pybind11_fixtures/expected_stubs_no_docs/pybind11_fixtures}/demo.pyi (100%) rename test-data/{pybind11_mypy_demo/expected_stubs_with_docs/pybind11_mypy_demo => pybind11_fixtures/expected_stubs_with_docs/pybind11_fixtures}/__init__.pyi (100%) rename test-data/{pybind11_mypy_demo/expected_stubs_with_docs/pybind11_mypy_demo => pybind11_fixtures/expected_stubs_with_docs/pybind11_fixtures}/demo.pyi (70%) rename test-data/{pybind11_mypy_demo => pybind11_fixtures}/pyproject.toml (100%) rename test-data/{pybind11_mypy_demo => pybind11_fixtures}/setup.py (85%) rename test-data/{pybind11_mypy_demo => pybind11_fixtures}/src/main.cpp (99%) diff --git a/.github/workflows/test_stubgenc.yml b/.github/workflows/test_stubgenc.yml index a2fb3e9dce6b..3daf01372d2d 100644 --- a/.github/workflows/test_stubgenc.yml +++ b/.github/workflows/test_stubgenc.yml @@ -1,4 +1,4 @@ -name: Test stubgenc on pybind11-mypy-demo +name: Test stubgenc on pybind11_fixtures on: workflow_dispatch: diff --git a/misc/test-stubgenc.sh b/misc/test-stubgenc.sh index 5ef23a72e832..ad66722628d8 100755 --- a/misc/test-stubgenc.sh +++ b/misc/test-stubgenc.sh @@ -7,7 +7,7 @@ cd "$(dirname "$0")/.." # Install dependencies, demo project and mypy python -m pip install -r test-requirements.txt -python -m pip install ./test-data/pybind11_mypy_demo +python -m pip install ./test-data/pybind11_fixtures python -m pip install . EXIT=0 @@ -17,7 +17,7 @@ EXIT=0 # everything else is passed to stubgen as its arguments function stubgenc_test() { # Remove expected stubs and generate new inplace - STUBGEN_OUTPUT_FOLDER=./test-data/pybind11_mypy_demo/$1 + STUBGEN_OUTPUT_FOLDER=./test-data/pybind11_fixtures/$1 rm -rf "${STUBGEN_OUTPUT_FOLDER:?}" stubgen -o "$STUBGEN_OUTPUT_FOLDER" "${@:2}" @@ -38,8 +38,8 @@ function stubgenc_test() { } # create stubs without docstrings -stubgenc_test expected_stubs_no_docs -p pybind11_mypy_demo +stubgenc_test expected_stubs_no_docs -p pybind11_fixtures # create stubs with docstrings -stubgenc_test expected_stubs_with_docs -p pybind11_mypy_demo --include-docstrings +stubgenc_test expected_stubs_with_docs -p pybind11_fixtures --include-docstrings exit $EXIT diff --git a/test-data/pybind11_mypy_demo/expected_stubs_no_docs/pybind11_mypy_demo/__init__.pyi b/test-data/pybind11_fixtures/expected_stubs_no_docs/pybind11_fixtures/__init__.pyi similarity index 100% rename from test-data/pybind11_mypy_demo/expected_stubs_no_docs/pybind11_mypy_demo/__init__.pyi rename to test-data/pybind11_fixtures/expected_stubs_no_docs/pybind11_fixtures/__init__.pyi diff --git a/test-data/pybind11_mypy_demo/expected_stubs_no_docs/pybind11_mypy_demo/demo.pyi b/test-data/pybind11_fixtures/expected_stubs_no_docs/pybind11_fixtures/demo.pyi similarity index 100% rename from test-data/pybind11_mypy_demo/expected_stubs_no_docs/pybind11_mypy_demo/demo.pyi rename to test-data/pybind11_fixtures/expected_stubs_no_docs/pybind11_fixtures/demo.pyi diff --git a/test-data/pybind11_mypy_demo/expected_stubs_with_docs/pybind11_mypy_demo/__init__.pyi b/test-data/pybind11_fixtures/expected_stubs_with_docs/pybind11_fixtures/__init__.pyi similarity index 100% rename from test-data/pybind11_mypy_demo/expected_stubs_with_docs/pybind11_mypy_demo/__init__.pyi rename to test-data/pybind11_fixtures/expected_stubs_with_docs/pybind11_fixtures/__init__.pyi diff --git a/test-data/pybind11_mypy_demo/expected_stubs_with_docs/pybind11_mypy_demo/demo.pyi b/test-data/pybind11_fixtures/expected_stubs_with_docs/pybind11_fixtures/demo.pyi similarity index 70% rename from test-data/pybind11_mypy_demo/expected_stubs_with_docs/pybind11_mypy_demo/demo.pyi rename to test-data/pybind11_fixtures/expected_stubs_with_docs/pybind11_fixtures/demo.pyi index c55376eff5c3..1527225ed009 100644 --- a/test-data/pybind11_mypy_demo/expected_stubs_with_docs/pybind11_mypy_demo/demo.pyi +++ b/test-data/pybind11_fixtures/expected_stubs_with_docs/pybind11_fixtures/demo.pyi @@ -10,15 +10,15 @@ class Point: degree: ClassVar[Point.AngleUnit] = ... radian: ClassVar[Point.AngleUnit] = ... def __init__(self, value: int) -> None: - """__init__(self: pybind11_mypy_demo.demo.Point.AngleUnit, value: int) -> None""" + """__init__(self: pybind11_fixtures.demo.Point.AngleUnit, value: int) -> None""" def __eq__(self, other: object) -> bool: """__eq__(self: object, other: object) -> bool""" def __hash__(self) -> int: """__hash__(self: object) -> int""" def __index__(self) -> int: - """__index__(self: pybind11_mypy_demo.demo.Point.AngleUnit) -> int""" + """__index__(self: pybind11_fixtures.demo.Point.AngleUnit) -> int""" def __int__(self) -> int: - """__int__(self: pybind11_mypy_demo.demo.Point.AngleUnit) -> int""" + """__int__(self: pybind11_fixtures.demo.Point.AngleUnit) -> int""" def __ne__(self, other: object) -> bool: """__ne__(self: object, other: object) -> bool""" @property @@ -33,15 +33,15 @@ class Point: mm: ClassVar[Point.LengthUnit] = ... pixel: ClassVar[Point.LengthUnit] = ... def __init__(self, value: int) -> None: - """__init__(self: pybind11_mypy_demo.demo.Point.LengthUnit, value: int) -> None""" + """__init__(self: pybind11_fixtures.demo.Point.LengthUnit, value: int) -> None""" def __eq__(self, other: object) -> bool: """__eq__(self: object, other: object) -> bool""" def __hash__(self) -> int: """__hash__(self: object) -> int""" def __index__(self) -> int: - """__index__(self: pybind11_mypy_demo.demo.Point.LengthUnit) -> int""" + """__index__(self: pybind11_fixtures.demo.Point.LengthUnit) -> int""" def __int__(self) -> int: - """__int__(self: pybind11_mypy_demo.demo.Point.LengthUnit) -> int""" + """__int__(self: pybind11_fixtures.demo.Point.LengthUnit) -> int""" def __ne__(self, other: object) -> bool: """__ne__(self: object, other: object) -> bool""" @property @@ -60,38 +60,38 @@ class Point: """__init__(*args, **kwargs) Overloaded function. - 1. __init__(self: pybind11_mypy_demo.demo.Point) -> None + 1. __init__(self: pybind11_fixtures.demo.Point) -> None - 2. __init__(self: pybind11_mypy_demo.demo.Point, x: float, y: float) -> None + 2. __init__(self: pybind11_fixtures.demo.Point, x: float, y: float) -> None """ @overload def __init__(self, x: float, y: float) -> None: """__init__(*args, **kwargs) Overloaded function. - 1. __init__(self: pybind11_mypy_demo.demo.Point) -> None + 1. __init__(self: pybind11_fixtures.demo.Point) -> None - 2. __init__(self: pybind11_mypy_demo.demo.Point, x: float, y: float) -> None + 2. __init__(self: pybind11_fixtures.demo.Point, x: float, y: float) -> None """ def as_list(self) -> List[float]: - """as_list(self: pybind11_mypy_demo.demo.Point) -> List[float]""" + """as_list(self: pybind11_fixtures.demo.Point) -> List[float]""" @overload def distance_to(self, x: float, y: float) -> float: """distance_to(*args, **kwargs) Overloaded function. - 1. distance_to(self: pybind11_mypy_demo.demo.Point, x: float, y: float) -> float + 1. distance_to(self: pybind11_fixtures.demo.Point, x: float, y: float) -> float - 2. distance_to(self: pybind11_mypy_demo.demo.Point, other: pybind11_mypy_demo.demo.Point) -> float + 2. distance_to(self: pybind11_fixtures.demo.Point, other: pybind11_fixtures.demo.Point) -> float """ @overload def distance_to(self, other: Point) -> float: """distance_to(*args, **kwargs) Overloaded function. - 1. distance_to(self: pybind11_mypy_demo.demo.Point, x: float, y: float) -> float + 1. distance_to(self: pybind11_fixtures.demo.Point, x: float, y: float) -> float - 2. distance_to(self: pybind11_mypy_demo.demo.Point, other: pybind11_mypy_demo.demo.Point) -> float + 2. distance_to(self: pybind11_fixtures.demo.Point, other: pybind11_fixtures.demo.Point) -> float """ @property def length(self) -> float: ... diff --git a/test-data/pybind11_mypy_demo/pyproject.toml b/test-data/pybind11_fixtures/pyproject.toml similarity index 100% rename from test-data/pybind11_mypy_demo/pyproject.toml rename to test-data/pybind11_fixtures/pyproject.toml diff --git a/test-data/pybind11_mypy_demo/setup.py b/test-data/pybind11_fixtures/setup.py similarity index 85% rename from test-data/pybind11_mypy_demo/setup.py rename to test-data/pybind11_fixtures/setup.py index 0da1cfbcef19..e227b49935ea 100644 --- a/test-data/pybind11_mypy_demo/setup.py +++ b/test-data/pybind11_fixtures/setup.py @@ -5,14 +5,14 @@ # Documentation: https://pybind11.readthedocs.io/en/stable/compiling.html ext_modules = [ Pybind11Extension( - "pybind11_mypy_demo", + "pybind11_fixtures", ["src/main.cpp"], cxx_std=17, ), ] setup( - name="pybind11-mypy-demo", + name="pybind11_fixtures", version="0.0.1", ext_modules=ext_modules, ) diff --git a/test-data/pybind11_mypy_demo/src/main.cpp b/test-data/pybind11_fixtures/src/main.cpp similarity index 99% rename from test-data/pybind11_mypy_demo/src/main.cpp rename to test-data/pybind11_fixtures/src/main.cpp index 8074e4b2d9e8..f41f7c799030 100644 --- a/test-data/pybind11_mypy_demo/src/main.cpp +++ b/test-data/pybind11_fixtures/src/main.cpp @@ -250,7 +250,7 @@ void bind_demo(py::module& m) { // Module entry point // ---------------------------------------------------------------------------- -PYBIND11_MODULE(pybind11_mypy_demo, m) { +PYBIND11_MODULE(pybind11_fixtures, m) { bind_test_cases(m); auto demo = m.def_submodule("demo");