我正在尝试组合一些由 pybind11 创建的模块,但不幸的是无法使其工作。希望有人可以帮忙。我已经尝试尽可能地简化问题。
我正在尝试创建以下两个模块:
point: 可以直接调用line:可以直接调用,也使用point模块。点.h:
#ifndef UNTITLED1_POINT_H
#define UNTITLED1_POINT_H
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
namespace py = pybind11;
class Point {
private:
double m_x;
double m_y;
double m_z;
public:
Point()= default;
Point(double x, double y, double z);
};
PYBIND11_MODULE(point, m) {
py::class_<Point>(m, "Point")
.def(py::init<double, double, double>());
}
#endif //UNTITLED1_POINT_H
Run Code Online (Sandbox Code Playgroud)
点.cpp:
#include "point.h"
Point::Point (double x, double y, double z){
m_x = x;
m_y = y;
m_z = z;
}
Run Code Online (Sandbox Code Playgroud)
行.h:
#ifndef UNTITLED1_LINE_H
#define UNTITLED1_LINE_H
#include <pybind11/pybind11.h> …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试使用Sphinx实现自动文档创建(使用扩展名sphinx-apidoc和napoleon)。这很好用,但是如果将typehints(PEP484约定)自动添加到params列表中会更好。
我想知道这是否可能。
更具体地说:(从拿破仑的例子)
def function_with_pep484_type_annotations(param1: int, param2: str) -> bool:
"""Example function with PEP 484 type annotations.
Args:
param1: The first parameter.
param2: The second parameter.
Returns:
The return value. True for success, False otherwise.
"""
Run Code Online (Sandbox Code Playgroud)
如下所示:
参数列表包含所有参数,但不附加类型。可以手动添加它们,但是当决定更改签名时,这可能会带来将来的问题。
手动添加类型的示例:
def function_with_pep484_type_annotations(param1: int, param2: str) -> bool:
"""Example function with PEP 484 type annotations.
Args:
param1 (int): The first parameter.
param2 (str): The second parameter.
Returns:
The return value. True for success, False otherwise.
"""
Run Code Online (Sandbox Code Playgroud)
呈现为:
python type-hinting python-sphinx sphinx-napoleon sphinx-apidoc