Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #90358

Re: [Python-Dev] anomaly

References <CAMjeLr--RfnfgWc1hdOcHiEBpq3QwC7SZk-m14wM65JtpbgMLQ@mail.gmail.com>
Date 2015-05-11 09:12 +0100
Subject Re: [Python-Dev] anomaly
From Paul Moore <p.f.moore@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.349.1431331954.12865.python-list@python.org> (permalink)

Show all headers | View raw


On 10 May 2015 at 17:34, Mark Rosenblitt-Janssen
<dreamingforward@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
'Hello'

Paul

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: [Python-Dev] anomaly Paul Moore <p.f.moore@gmail.com> - 2015-05-11 09:12 +0100

csiph-web