Why new Python 2.5 feature "class C()" return old-style class ?

Bengt Richter bokr at oz.net
Tue Apr 25 03:21:22 EDT 2006


On Sun, 23 Apr 2006 22:12:01 GMT, bokr at oz.net (Bengt Richter) wrote:
[...]
>(IMO the proper way to indicate the you don't have a tuple is to use None or some other sentinel,
>not abuse a perfectly legal tuple value).
>
> >>> dis.dis(compile('class X:pass','','exec'))
>   1           0 LOAD_CONST               0 ('X')   <<--+-- ought to be LOAD_CONST 0 (None)
Oops, leave the 'X' of course, just replace the next line
>               3 BUILD_TUPLE              0         <<--'
>               6 LOAD_CONST               1 (<code object X at 02EE7EA0, file "", line 1>)
>               9 MAKE_FUNCTION            0
>              12 CALL_FUNCTION            0
>              15 BUILD_CLASS
>              16 STORE_NAME               0 (X)
>              19 LOAD_CONST               2 (None)
>              22 RETURN_VALUE
>
>vs code for class x(something):pass
>
> >>> dis.dis(compile('class X(object):pass','','exec'))
>   1           0 LOAD_CONST               0 ('X')
>               3 LOAD_NAME                0 (object)
>               6 BUILD_TUPLE              1
>               9 LOAD_CONST               1 (<code object X at 02EFB9A0, file "", line 1>)
>              12 MAKE_FUNCTION            0
>              15 CALL_FUNCTION            0
>              18 BUILD_CLASS
>              19 STORE_NAME               1 (X)
>              22 LOAD_CONST               2 (None)
>              25 RETURN_VALUE
>

Regards,
Bengt Richter



More information about the Python-list mailing list