Re: [Python-Dev] anomaly

In case the example given at the start of the thread wasn't interesting enough, it also works in the other direction:
class str(int): pass
str('2')
2 #<----- an integer!!!
Mark

* Mark Rosenblitt-Janssen dreamingforward@gmail.com [2015-05-10 11:34:52 -0500]:
Here's something that might be wrong in Python (tried on v2.7):
class int(str): pass
int(3)
'3'
What's so odd about this? "class int" is an assignment to "int", i.e. what you're doing here is basically:
int = str int(3) # really str(3)
* Mark Rosenblitt-Janssen dreamingforward@gmail.com [2015-05-10 19:14:18 -0500]:
In case the example given at the start of the thread wasn't interesting enough, it also works in the other direction:
class str(int): pass
str('2')
2 #<----- an integer!!!
Same thing. You're shadowing the builtin.
Florian

On 5/11/2015 3:40 AM, Florian Bruhin wrote:
[snip]
This trollish thread was cross-posted to python-list, where it was semi-ok, at least in the beginning, and pydev, where it is not. It has continued on python-list with pydev removed. Please do not continue it here (on pydev).
participants (3)
-
Florian Bruhin
-
Mark Rosenblitt-Janssen
-
Terry Reedy