-
Notifications
You must be signed in to change notification settings - Fork 243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incompatible with nanobind 2.2 on Py3.12 #789
Labels
Comments
cmake_minimum_required(VERSION 3.15...3.27)
project(my_project) # Replace 'my_project' with the name of your project
if (CMAKE_VERSION VERSION_LESS 3.18)
set(DEV_MODULE Development)
else()
set(DEV_MODULE Development.Module)
endif()
find_package(Python 3.8 COMPONENTS Interpreter ${DEV_MODULE} REQUIRED)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
execute_process(
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE nanobind_ROOT)
find_package(nanobind CONFIG REQUIRED)
nanobind_add_module(my_ext my_ext.cpp) #include <nanobind/nanobind.h>
#include <iostream>
struct MyType {
MyType() {}};
NB_MODULE(my_ext, m) {
nanobind::class_<MyType>(m, "MyType", nanobind::dynamic_attr())
.def("__init__",
[](MyType *t, int bar)
{
std::cout << "C++ __init__ " << bar << std::endl;
new (t) MyType();
});
} from my_ext import MyType
def my_init(self, s:str): # different arg type compared to C++
print("python __init__", s)
MyType.__init__ = my_init
MyType(42)
MyType("foo")
Edit: Turns out this is specific to Python 3.12; with that version, the reproducer above shows the issue. |
This comment was marked as outdated.
This comment was marked as outdated.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As pointed out by @matthiasdiener in #788.
Example:
We'll probably need to avoid overriding
__init__
the way we have. The easiest way to do this may be to just port the existing constructors to C++.The text was updated successfully, but these errors were encountered: