[Python-Dev] PyInstance_Check() and new-style classes

Greg Ewing greg at cosc.canterbury.ac.nz
Tue Jul 13 05:06:46 CEST 2004


Eric Wilhelm <ewilhelm at sbcglobal.net>:

> +       if ((obj->ob_type->tp_flags & Py_TPFLAGS_HEAPTYPE) || 
>           PyInstance_Check(obj)) {

I don't understand why you need to make this check.
Aren't you going to have to check individually anyway for all
the types you want to treat specially? If so, why not just

  if (PyString_CheckExact(obj)) {
    /* convert it to a Perl string */
  }
  elif (PyInt_CheckExact(obj)) {
    /* convert it to a Perl integer */
  }
  ...
  else {
    /* None of the above, wrap it generically */
  }

Using the CheckExact macros will ensure that you don't pick
up any subclasses of the built-in types.

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg at cosc.canterbury.ac.nz	   +--------------------------------------+


More information about the Python-Dev mailing list