I found some very odd behaviour in Python's very basic types
Terry Reedy
tjreedy at udel.edu
Thu Mar 10 01:01:11 EST 2011
On 3/10/2011 12:47 AM, Sunjay Varma 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.
No, that is fundamentally wrong. Rebinding a name in a particular
namespace only deletes the association in that namespace.
Built-in classes are just that. You cannot get rid of them. They are
used in the operation of the interpreter.
> For some reason though,
> even though the interpreter says that str == type("hello"),
> overwriting the str name changes nothing in the literal.
Right. By design. String and number literals are always string and
number literals.
> Is this a bug?
No.
--
Terry Jan Reedy
More information about the Python-list
mailing list