meta-class troubles

Chris Rebert clp2 at rebertia.com
Mon Aug 30 16:17:24 CEST 2010


On Mon, Aug 30, 2010 at 7:10 AM, Ethan Furman <ethan at stoneleaf.us> wrote:
> Good Day!
>
> I am stuck... hopefully a few fresh pairs of eyes will spot what I am
> missing.
>
> I have a metaclass, Traits, and two different testing files, test_traits.py
> and tests.py.  test_traits works fine, tests generates the following error:
>
> C:\Python31\Lib\site-packages\traits\tests>\python31\python tests.py
> Traceback (most recent call last):
>  File "tests.py", line 4, in <module>
>    class TraitConflict(meta=Traits, traits=(BoxPrint, BigBoxPrint)):
> TypeError: type() takes 1 or 3 arguments
>
>
> Working code from test_traits.py:
> class DerivedClass(metaclass=Traits, traits=(TBundle1, TBundle2)):
>    def repeat(yo, text, count):
>        print('whatever...')
>    def whatsit(yo, arg1):
>        print("calling baseclass's whatsit...")
>        print(super().whatsit(arg1))
>
> Failing code from tests.py:
> class TraitConflict(meta=Traits, traits=(BoxPrint, BigBoxPrint)):
>    def useless(yo):
>        print("this class won't compile")

Shouldn't meta= instead be metaclass= ?

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list