Skip to content

Subtypes of extension type appear to inherit Py_TPFLAGS_DISALLOW_INSTANTIATION flag #96746

Closed
@chgnrdv

Description

@chgnrdv

When Py_TPFLAGS_BASETYPE and Py_TPFLAGS_DISALLOW_INSTANTIATION flags are set on extension type tp_flags field, attempt to create type subclass instance fails:

>>> import _foo
>>> class Bar(_foo.Foo): pass
... 
>>> Bar()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: cannot create 'Bar' instances

According to documentation, it shouldn't happen:
https://docs.python.org/3/c-api/typeobj.html#Py_TPFLAGS_DISALLOW_INSTANTIATION

Extension code example:
_foo.c.txt

Tested on 3.10.3 and 3.12.0a0.

Metadata

Metadata

Assignees

Labels

docsDocumentation in the Doc dir

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions