mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
* Objects/classobject.c, Include/classobject.h: added __getattr__
and __setattr__ support to override getattr(x, name) and setattr(x, name, value) for class instances. This uses a special hack whereby the class is supposed to be static: the __getattr__ and __setattr__ methods are looked up only once and saved in the instance structure for speed
This commit is contained in:
parent
e025e31de6
commit
e149fa2a1e
2 changed files with 111 additions and 17 deletions
|
@ -30,6 +30,12 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
/* Class object interface */
|
||||
|
||||
#ifdef WITH_THREAD
|
||||
#include "thread.h"
|
||||
#else
|
||||
#define get_thread_ident() 1L
|
||||
#endif
|
||||
|
||||
/* Revealing some structures (not for general use) */
|
||||
|
||||
typedef struct {
|
||||
|
@ -43,6 +49,12 @@ typedef struct {
|
|||
OB_HEAD
|
||||
classobject *in_class; /* The class object */
|
||||
object *in_dict; /* A dictionary */
|
||||
object *in_getattr; /* A method or NULL */
|
||||
object *in_setattr; /* A method or NULL */
|
||||
long in_ident; /* A thread ident or 0 */
|
||||
#ifdef WITH_THREAD
|
||||
type_lock *in_lock; /* A lock or NULL */
|
||||
#endif
|
||||
} instanceobject;
|
||||
|
||||
extern typeobject Classtype, Instancetype, Instancemethodtype;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue