I found some very odd behaviour in Python's very basic types

John Roth johnroth1 at gmail.com
Thu Mar 10 12:05:43 EST 2011


On Mar 9, 10:47 pm, Sunjay Varma <varma.sun... at gmail.com> wrote:
> For some reason, sub-classing and overwriting a built-in type does not
> change the behavior of the literal. Logically speaking, overwriting a
> name, such as str, should delete the basic str type, and replace it
> with the new class or object put in its place. For some reason though,
> even though the interpreter says that str == type("hello"),
> overwriting the str name changes nothing in the literal. Is this a
> bug? I'm not sure.
>
> -Sunjay03

This is neither a bug nor a feature, it's simply the way that
Python works. Literals are handled during compilation; the built-in
types are run-time objects.

Python is not a language where a script can change compile-time
behavior. Doing that would make it a very different language, and
would put it into a very different niche in the language ecology.

John Roth



More information about the Python-list mailing list