subclassable types

Daniel Urban urban.dani at gmail.com
Fri Feb 22 18:26:36 CET 2013


On Fri, Feb 22, 2013 at 12:00 PM, Christian Heimes <christian at python.org> wrote:
> Am 22.02.2013 10:35, schrieb Wolfgang Maier:
>> Also: can you use introspection to find out whether a type is valid as a
>> base type?
>
> I don't think so. For CPython the information is stored in the type's
> structure. When type->tp_flags & Py_TPFLAGS_BASETYPE is true then
> subclassing is allowed. But I know of no way to retrieve that
> information from Python code.

There is an (undocumented and CPython-specific) way:

>>> range.__flags__ & (1 << 10)
0
>>> int.__flags__ & (1 << 10)
1024



Daniel



More information about the Python-list mailing list