Casting classes WAS: Documenting builtin methods

Christian Heimes christian at python.org
Fri Jul 12 03:21:14 CEST 2013


Am 12.07.2013 02:23, schrieb Mark Janssen:
> A user was wondering why they can't change a docstring in a module's class.

For CPython builtin types (classes) and function have read-only doc
strings for multiple reasons. Internally the doc strings are stored as
constant C string literals. The __doc__ attribute is implemented as
descriptor that turns the const char *tp_doc member into a Python
string. const char* are ... constant. :)

All types and builtins are shared across all subinterpreters of Python.
The types and their doc strings are identical. Most people are not aware
of the subinterpreter feature. Subinterpreters run in different threads
of the same process but are isolated from each other. Mutable type and
builtin doc strings would break the isolation. You could share
information between subinterpreters by e.g. setting the doc string of
the int type. We don't want that.

Heap types (classes defined with Python code) are not shared. The same
goes to modules, even the sys module.

Christian




More information about the Python-list mailing list