type() new style class instance says "class", not "ObjectType"

David Mertz, Ph.D. mertz at gnosis.cx
Fri Apr 12 15:46:01 EDT 2002


"David Mertz, Ph.D." wrote:
|A list is a mutable sequence that has some items in it.  In contrast, an
|instance object--whether new style or old style (and w/ or w/o
|__slots__)--is a thing that has some attributes.  The basic shape of the
|data will always be different.

Guido van Rossum <guido at python.org> wrote previously:
|    class D(list):
|        __slots__ = ["foo"]
|List or instance?  The shape of a D instance is the same
|as the shape of a list, but with an extra slot added.

It seems like the shape of this data is different from either an
old-style list or an old-style instance.  There are several standard
modules (or even builtins) that have questionable--and probably
wrong--behavior around this:

    >>> d = D()
    >>> d.append('this')
    >>> d.foo = 'foo'
    >>> import pprint
    >>> pprint.pprint(d)
    ['this']
    >>> from pickle import dumps, loads
    >>> d2 = loads(dumps(d))
    >>> d2.foo
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    AttributeError: foo
    >>> repr(d)
    "['this']"

Moreover, xml_pickle in particular has an extra burden here, above and
beyond what pickle does.  The XML representation wants to be fairly
human-readable (which I think it is so far).  This requirement is not
really there for pickle itself.

But xml_pickle also wants to be cross-language; that's why there is a
DTD associated with the dialect, for example.  Other programming
languages should be able to read xml_pickle files, and create native
objects that provide at least a pretty good approximation of the data
structures contained in the Python objects.  And likewise going the
other direction.  As such, I take "sequence" or "map" to be general
families of data "shapes" that many languages use.  These basic shapes
should therefore be indicated in the XML (while also providing clues for
the more specific data containers used).

Yours, David...

--
    _/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY: Postmodern Enterprises _/_/_/
   _/_/    ~~~~~~~~~~~~~~~~~~~~[mertz at gnosis.cx]~~~~~~~~~~~~~~~~~~~~~  _/_/
  _/_/  The opinions expressed here must be those of my employer...   _/_/
 _/_/_/_/_/_/_/_/_/_/ Surely you don't think that *I* believe them!  _/_/






More information about the Python-list mailing list