[Python-checkins] r54545 - in python/trunk: Lib/string.py Objects/typeobject.c

Guido van Rossum guido at python.org
Fri Mar 23 21:26:06 CET 2007


The asserts are checking that we haven't somehow gotten screwy
arguments. If they ever trigger, some other C code (in the same file
or in a user extension) is to blame, not the user's argument list. But
asserts only trigger in debug builds; the other checks are for extra
robustness against user extensions screwiness in non-debug builds.

(Why did you rearrange the lines in your quotation? That confused the
heck out of me.)

On 3/23/07, Jim Jewett <jimjjewett at gmail.com> wrote:
> Why just assert?  You're checking it every run-time anyhow, so you
> might as well raise an error.  Or is the assert secretly acting as a
> compiler directive as well?
>
> On 3/23/07, guido.van.rossum <python-checkins at python.org> wrote:
> ==============================================================================
> > --- python/trunk/Objects/typeobject.c   (original)
> > +++ python/trunk/Objects/typeobject.c   Fri Mar 23 19:53:03 2007
>
> > +type_init(PyObject *cls, PyObject *args, PyObject *kwds)
> > +{
>
> ...
>
> > +       assert(kwds == NULL || PyDict_Check(kwds));
> ...
> > +       if (kwds != NULL && PyDict_Check(kwds) && PyDict_Size(kwds) != 0) {
> > +               PyErr_SetString(PyExc_TypeError,
> > +                               "type.__init__() takes no keyword arguments");
> > +               return -1;
> > +       }
>
>
> > +       assert(args != NULL && PyTuple_Check(args));
> ...
> > +       if (args != NULL && PyTuple_Check(args) &&
> > +           (PyTuple_GET_SIZE(args) != 1 && PyTuple_GET_SIZE(args) != 3)) {
> > +               PyErr_SetString(PyExc_TypeError,
> > +                               "type.__init__() takes 1 or 3 arguments");
> > +               return -1;
> > +       }
>
>
> -jJ
>


-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-checkins mailing list