Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue7278] decimal.py: New instance vs. new reference

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Nov 7, 2009, 1:51 AM

Post #1 of 4 (226 views)
Permalink
[issue7278] decimal.py: New instance vs. new reference

New submission from Stefan Krah <stefan-usenet [at] bytereef>:

In the following case, Decimal() and int() behave differently. I wonder
if this is intentional:

>>> from decimal import *
>>> x = Decimal(2)
>>> y = Decimal(x)
>>> id(x) == id(y)
False
>>>
>>> x = int(2)
>>> y = int(x)
>>> id(x) == id(y)
True
>>>

----------
messages: 95015
nosy: mark.dickinson, skrah
severity: normal
status: open
title: decimal.py: New instance vs. new reference

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7278>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 7, 2009, 12:42 PM

Post #2 of 4 (220 views)
Permalink
[issue7278] decimal.py: New instance vs. new reference [In reply to]

Changes by Stefan Krah <stefan-usenet [at] bytereef>:


----------
type: -> behavior

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7278>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 7, 2009, 4:14 PM

Post #3 of 4 (212 views)
Permalink
[issue7278] decimal.py: New instance vs. new reference [In reply to]

Mark Dickinson <dickinsm [at] gmail> added the comment:

I don't think it should matter whether either 'id(x) == id(y)' returns
True or False: since both ints and Decimals are regarded as immutable,
the implementation should be free to reuse (or not) existing objects at
will.

There is a test in test_decimal.py that seems to expect that Decimal(x)
always returns a copy. I'm not quite sure why that test is there,
though it may be because Decimal instances weren't always as immutable
as they are now (some of the non-__new__ methods used to modify the
Decimal fields directly). In my opinion that test could be removed, but
I'd like to consult with some of the other Decimal authors before doing
so.

(An aside: it's important to note that operations on Decimal subclasses
should always return *Decimal* instances, not instances of the subclass.
So any code like:

if isinstance(x, Decimal): return x

should be regarded with suspicion.)

N.B. Some of your recent reports seem more like questions about the
implementation rather than reports of possible bugs in Python; I'm not
sure that the bug tracker is the best medium for this. python-dev might
be more appropriate, or I'm happy to answer private emails.

----------

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7278>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Nov 7, 2009, 10:40 PM

Post #4 of 4 (211 views)
Permalink
[issue7278] decimal.py: New instance vs. new reference [In reply to]

Raymond Hettinger <rhettinger [at] users> added the comment:

Stefan, this is a non-guaranteed implementation detail (for both ints
and decimals).

----------
nosy: +rhettinger
resolution: -> invalid
status: open -> closed

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue7278>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.