[Python-Dev] anomaly

Paul Moore p.f.moore at gmail.com
Mon May 11 10:12:24 CEST 2015

On 10 May 2015 at 17:34, Mark Rosenblitt-Janssen
<dreamingforward at gmail.com> wrote:
> Here's something that might be wrong in Python (tried on v2.7):
>>>> class int(str): pass
>>>> int(3)
> '3'

It's not wrong as such. It is allowed to define your own class that
subclasses a builtin class, and it's allowed to shadow builtin names.
So while this is (obviously) bad practice, it's not wrong.

For a simpler example:

Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600
64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> str
<class 'str'>
>>> str = "Hello"
>>> str


More information about the Python-Dev mailing list