Skip to content

Commit

Permalink
test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rath3t committed Aug 20, 2024
1 parent d21cee3 commit 379aae7
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/pybind11/functional.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "pybind11.h"

#include <functional>
#include <iostream>

PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
PYBIND11_NAMESPACE_BEGIN(detail)
Expand Down Expand Up @@ -138,17 +139,27 @@ struct type_caster<std::function<Return(Args...)>> {
};
size_t argCount = 0;

std::cout << "BEFORE codeAttr is not null" << std::endl;
handle codeAttr = PyObject_GetAttrString(src.ptr(), "__code__");
std::cout << "AFTER codeAttr is not null" << std::endl;
if (codeAttr) {
std::cout << "codeAttr is not null" << std::endl;
argCount = argCountFromFuncCode(codeAttr);
} else {
std::cout << "BEFORE callAttr is not null" << std::endl;
handle callAttr = PyObject_GetAttrString(src.ptr(), "__call__");
std::cout << "AFTER callAttr is not null" << std::endl;
if (callAttr) {
std::cout << "BEFORE codeAttr2 is not null" << std::endl;
handle codeAttr2 = PyObject_GetAttrString(callAttr.ptr(), "__code__");
std::cout << "AFTER codeAttr2 is not null" << std::endl;
argCount = argCountFromFuncCode(codeAttr2)
- 1; // we have to remove the self argument
} else {
// No __code__ or __call__ attribute, this is not a proper Python function
std::cout << "No __code__ or __call__ attribute, this is not a proper Python "
"function"
<< std::endl;
return false;
}
}
Expand Down

0 comments on commit 379aae7

Please sign in to comment.