Skip to content

datetime_strptime is 'NoneType' when restart cpython#117914

@marin-man

Description

@marin-man

Bug report

Bug description:

When executing the following code, it will appear TypeError: 'NoneType' object is not callable

#include"Python.h" #include<iostream>voidpy_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()} intmain(){py_test(); std::cout << "========" << std::endl; py_test(); return0}

CPython versions tested on:

3.11

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions