Skip to content

MetaClass tp_new == NULL needs to be rejected in Python for type(...) #151912

Description

@seberg

Bug report

Bug description:

# `metaclass_instance == np.dtype` for NumPy main
type("name", metaclass_instance, {})

for metaclasses that have tp_new == NULL is well defined: It has to be a Python error just like:

>>> type(metaclass_instace)()
TypeError: cannot create 'numpy._DTypeMeta' instances

(in this case a NumPy metaclass, but you need the main branch of NumPy to test this.)

That is, a metaclass that is a valid baseclass in C but has tp_new == NULL cannot be instantiated from Python but hits this code branch:

*type = winner->tp_new(winner, ctx->args, ctx->kwds);

Which clearly segfaults for tp_new == NULL.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions