473,398 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Identity inconsistency and unification of types and classes

Rim
Hi,

With the great unification of types and classes, what will happen to the
following identity inconsistency?
class myint(int): pass .... a=int(1); b=int(1)
a is b 1 a=myint(1); b=myint(1)
a is b

0

Thanks
- Rim
Jul 18 '05 #1
3 1714
Rim wrote:
With the great unification of types and classes, what will happen to
the
following identity inconsistency?
class myint(int): pass ... a=int(1); b=int(1)
a is b 1 a=myint(1); b=myint(1)
a is b

0


Whether or not int(1) is int(1) is purely an optimization issue, so one
wonders why one would be concerned about it.

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ They have rights who dare defend them.
\__/ Roger Baldwin
Jul 18 '05 #2
ri*******@yahoo.com (Rim) writes:
Hi,

With the great unification of types and classes, what will happen to the
following identity inconsistency?
class myint(int): pass ... a=int(1); b=int(1)
a is b 1 a=myint(1); b=myint(1)
a is b

0


Nothing, as is. You can always dick about in myint.__new__ if you
really want to manage that, but as others keep saying, you shouldn't
worry about it too much.

Cheers,
M.

--
My hat is lined with tinfoil for protection in the unlikely event
that the droid gets his PowerPoint presentation working.
-- Alan W. Frame, alt.sysadmin.recovery
Jul 18 '05 #3

ri*******@yahoo.com (Rim) writes:
With the great unification of types and classes, what will happen to the
following identity inconsistency?
class myint(int): pass ... a=int(1); b=int(1)
a is b 1 a=myint(1); b=myint(1)
a is b 0
On Mon, 14 Jul 2003, Michael Hudson <mw*@python.net> wrote:
Nothing, as is. You can always dick about in myint.__new__ if you
really want to manage that, but as others keep saying, you shouldn't
worry about it too much.


Of course, the inconsistency has always been present:
int(1) is int(1) 1 int(5000) is int(2500*2)

0

Not so much with the consistency, huh?
Here's the deal: if a,b are immutable builtin objects, and a==b, it is
undefined if "a is b" is true. Do not rely on it. Assume patch releases
of Python will change it to be randomly true or false. Assume flags
to Python's compilation will randomly change it to true or false. Assume
the fluttering of the wings of a butterfly in Tibet will create a storm...
err, sorry, got carried away there.

Exercise: Determine for yourself where exactly I got carried away. Discuss.
--
Moshe Zadka -- http://moshez.org/
Buffy: I don't like you hanging out with someone that... short.
Riley: Yeah, a lot of young people nowadays are experimenting with shortness.
Agile Programming Language -- http://www.python.org/

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Roberto A. F. De Almeida | last post by:
I found that when using negative indices, the slice object passed to __getitem__ depends on the number of slices. An example to clarify: class a: def __getitem__(self, index): return index ...
46
by: Scott Chapman | last post by:
There seems to be an inconsistency here: Python 2.3.2 (#1, Oct 3 2003, 19:04:58) on linux2 >>> 1 == True True >>> 3 == True False >>> if 1: print "true" ....
11
by: Dietrich Epp | last post by:
Without invoking double-underscore black magic, it is possible to choose a, b, and c in Python such that: a < b b < c c < a This could cause sorting functions to malfunction. >>> class...
99
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less...
83
by: kartik | last post by:
there seems to be a serious problem with allowing numbers to grow in a nearly unbounded manner, as int/long unification does: it hides bugs. most of the time, i expect my numbers to be small. 2**31...
1
by: Clemens Hoffmann | last post by:
Hello, i have a nasty problem with object identity in hash tables. I try to use different objects as keys. It failed bacause i cannot identify object propperly. Different objects with the same...
37
by: spam.noam | last post by:
Hello, Guido has decided, in python-dev, that in Py3K the id-based order comparisons will be dropped. This means that, for example, "{} < " will raise a TypeError instead of the current...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.