Prothon, metaclasses, Zope [Was: A 'Python like' language]
Roberto Lupi
Roberto at lupi.an.it
Tue Mar 30 04:17:29 EST 2004
In article <95aa1afa.0403272243.78d60724 at posting.google.com>,
> So, I reverted my mind to the pre-metaclass functioning mode (which required
> a certain effort) and I wrote a function that takes a class, looks at
> its dictionary, and raises an error if the class overrides an attribute
> which is already defined in the parent classes. The solution works,
> but it is kind of ugly compared to the metaclass solution:
>
> 1. The metaclass can raise the error *before* the metaclass is created,
> whereas the function works a posteriori, *after* the overriding is done;
> if find it to be conceptually unsatisfactory, I don't want to create
> a class just to throw it away. The alternative is to use a class factory,
> but then I have just re-invented a metaclass with an ugly call syntax.
I would add the check to a test case for the class.
class XYZTestCase(ZopeTestCase):
tested_class = XYZ
def testOverriddenMethods(self):
check_if_we_are_overriding_names_in(self.tested_class)
> 2. The metaclass can be inherited, so the check is automatic for all children;
> on the contrary, I have to call the function by hand each time I define
> a new class. This means writing twice the class name, which is error
> prone if I later rename the class and I forget to update the function
> call.
Test cases can be inherited.
class XYZ2TestCase(XYZTestCase):
tested_class = XYZ2
--
Roberto Lupi
More information about the Python-list
mailing list