]> granicus.if.org Git - python/commit
Add checking for a number of metaclass error conditions.
authorJeremy Hylton <jeremy@alum.mit.edu>
Tue, 27 Feb 2007 18:29:45 +0000 (18:29 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Tue, 27 Feb 2007 18:29:45 +0000 (18:29 +0000)
commitfa955697fa0986b19abac7b026c8f00b4393adf9
tree33731c5bb7b7e6fee121763b7c29439f1cc97779
parent2d1f5c93bbe3ed6202e14e9d3c3708174b62f8e6
Add checking for a number of metaclass error conditions.

We add some new rules that are required for preserving internal
invariants of types.

1.  If type (or a subclass of type) appears in bases, it must appear
    before any non-type bases.  If a non-type base (like a regular
    new-style class) occurred first, it could trick type into
    allocating the new class an __dict__ which must be impossible.

2. There are several checks that are made of bases when creating a
   type.  Those checks are now repeated when assigning to __bases__.
   We also add the restriction that assignment to __bases__ may not
   change the metaclass of the type.

Add new tests for these cases and for a few other oddball errors that
were no previously tested.  Remove a crasher test that was fixed.

Also some internal refactoring:  Extract the code to find the most
derived metaclass of a type and its bases.  It is now needed in two
places.  Rewrite the TypeError checks in test_descr to use doctest.
The tests now clearly show what exception they expect to see.
Lib/test/crashers/modify_dict_attr.py [deleted file]
Lib/test/test_descr.py
Objects/typeobject.c