[Python-3000] bytes & Py_TPFLAGS_BASETYPE

Guido van Rossum guido at python.org
Sun Sep 16 19:02:09 CEST 2007


It is possible to compromise the integrity of a built-in type by
subclassing it if the type wasn't carefully written to expect
subclassing. The bytes type currently wasn't written to be careful
about this. Why can't you use containment instead of subclassing?

--Guido

On 9/16/07, Mathieu Fenniak <mathieu.fenniak at gmail.com> wrote:
> Hi everyone,
>
> I'd like to be able to derive from the bytes type, but this currently
> isn't possible due to it missing the Py_TPFLAGS_BASETYPE.  A comment
> next to the flags indicates that this class is "sealed / final".  I
> tried to search this list for some information on this, but I
> couldn't find any relevant posts.  Why is this type "sealed"?
>
> I've experimented by adding the basetype flag to the type (with a
> recent svn checkout).  Python's test suite continues to run without
> any errors after this change.  My own project's test suite works
> flawlessly with a bytes derived type, as well.  I expected to
> encounter some error or difficulty that would explain why this type
> wasn't usable as a base type, but it seems to work great.
>
> Mathieu
> _______________________________________________
> Python-3000 mailing list
> Python-3000 at python.org
> http://mail.python.org/mailman/listinfo/python-3000
> Unsubscribe: http://mail.python.org/mailman/options/python-3000/guido%40python.org
>


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


More information about the Python-3000 mailing list