mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
is a list of weak references to types (new-style classes). Make this accessible to Python as the function __subclasses__ which returns a list of types -- we don't want Python programmers to be able to manipulate the raw list. In order to make this possible, I also had to add weak reference support to type objects. This will eventually be used together with a trap on attribute assignment for dynamic classes for a major speed-up without losing the dynamic properties of types: when a __foo__ method is added to a class, the class and all its subclasses will get an appropriate tp_foo slot function.
This commit is contained in:
parent
4c398fde5c
commit
1c45073aba
2 changed files with 73 additions and 1 deletions
|
@ -289,6 +289,8 @@ typedef struct _typeobject {
|
|||
PyObject *tp_bases;
|
||||
PyObject *tp_mro; /* method resolution order */
|
||||
PyObject *tp_defined;
|
||||
PyObject *tp_subclasses;
|
||||
PyObject *tp_weaklist;
|
||||
|
||||
#ifdef COUNT_ALLOCS
|
||||
/* these must be last and never explicitly initialized */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue