diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2002-07-12 15:42:10 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2002-07-12 15:42:10 (GMT) |
commit | 98013be7977c613d8a1c5f0446a73d100ccc7b17 (patch) | |
tree | 547a24f7131975d26d654152e5225a7cff6e6d1a /Demo/newmetaclasses | |
parent | 58e2ff2e810261291b4690fdc075404008a564cd (diff) | |
download | cpython-98013be7977c613d8a1c5f0446a73d100ccc7b17.zip cpython-98013be7977c613d8a1c5f0446a73d100ccc7b17.tar.gz cpython-98013be7977c613d8a1c5f0446a73d100ccc7b17.tar.bz2 |
Get the meta class inheritance right.
Diffstat (limited to 'Demo/newmetaclasses')
-rw-r--r-- | Demo/newmetaclasses/Eiffel.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/Demo/newmetaclasses/Eiffel.py b/Demo/newmetaclasses/Eiffel.py index 3e68611..1dd7e6c 100644 --- a/Demo/newmetaclasses/Eiffel.py +++ b/Demo/newmetaclasses/Eiffel.py @@ -4,6 +4,11 @@ from new import function class EiffelBaseMetaClass(type): + def __new__(meta, name, bases, dict): + meta.convert_methods(dict) + return super(EiffelBaseMetaClass, meta).__new__(meta, name, bases, + dict) + def convert_methods(cls, dict): """Replace functions in dict with EiffelMethod wrappers. @@ -30,10 +35,6 @@ class EiffelBaseMetaClass(type): class EiffelMetaClass1(EiffelBaseMetaClass): # an implementation of the "eiffel" meta class that uses nested functions - def __new__(meta, name, bases, dict): - meta.convert_methods(dict) - return super(EiffelMetaClass1, meta).__new__(meta, name, bases, dict) - def make_eiffel_method(func, pre, post): def method(self, *args, **kwargs): if pre: @@ -80,7 +81,7 @@ class EiffelDescriptor(object): self._post(inst, x, *args, **kwargs) return x -class EiffelMetaClass2(EiffelMetaClass1): +class EiffelMetaClass2(EiffelBaseMetaClass): # an implementation of the "eiffel" meta class that uses descriptors make_eiffel_method = EiffelDescriptor |