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

Jim Jewett jimjjewett at gmail.com
Fri Mar 23 21:19:34 CET 2007


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


More information about the Python-checkins mailing list