8000 [BUG] Cython uses PyObject_GenericSetAttr() on types in Limited API · Issue #6323 · cython/cython · GitHub
[go: up one dir, main page]

Skip to content
[BUG] Cython uses PyObject_GenericSetAttr() on types in Limited API #6323
@scoder

Description

@scoder

Describe the bug

This code now hits an assertion in dev-builds of the CPython main branch:

#if CYTHON_COMPILING_IN_LIMITED_API
// Using PyObject_GenericSetAttr to bypass types immutability protection feels
// a little hacky, but it does work in the limited API .
// (It doesn't work on PyPy but that probably isn't a bug.)
result = PyObject_GenericSetAttr((PyObject*)tp, k, v);
#else

https://github.com/python/cpython/blob/e6fad7a0e3d824f4a3c9cd71a48208880606d705/Objects/object.c#L1714

    assert(!PyType_IsSubtype(tp, &PyType_Type));

This is used in the auto-reduce setup code to fix up the reduce methods after creating the type. The assertion was added in
python/cpython#118454

Not sure if there's a way to work around this – or whether we should. It seems to be a hack on our side to update the type dict like this (even after adding the type to the module dict).

Code to reproduce the behaviour:

No response

Expected behaviour

No response

OS

No response

Python version

3.14

Cython version

master

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0