Closed
Description
Bug report
Bug description:
When executing the following code, it will appear TypeError: 'NoneType' object is not callable
#include "Python.h"
#include <iostream>
void py_test() {
Py_Initialize();
auto pName = PyUnicode_DecodeFSDefault("datetime");
auto pModule = PyImport_Import(pName);
auto datetime = PyObject_GetAttrString(pModule, "datetime");
auto strptime = PyObject_GetAttrString(datetime, "strptime");
auto args = PyTuple_New(2);
PyTuple_SetItem(args, 0, PyUnicode_FromString("2000-01"));
PyTuple_SetItem(args, 1, PyUnicode_FromString("%Y-%m"));
auto res = PyObject_CallObject(strptime, args);
PyObject_Print(res, stdout, 0);
Py_Finalize();
}
int main() {
py_test();
std::cout << "========" << std::endl;
py_test();
return 0;
}
CPython versions tested on:
3.11
Operating systems tested on:
macOS
Linked PRs
Metadata
Metadata
Assignees
Labels
An unexpected behavior, bug, or errorAn unexpected behavior, bug, or error