Hi Kwankyu,

On 2012-05-03, Kwankyu Lee <[email protected]> wrote:
> I am not against using the string representation to compute the hash, as 
> the last resort. 

The result is that the hash is broken by default, since the string
representation can be changed *after* creation of the object, which
means that the hash value would change as well. There is a ticket fixing
it, though.

> I think the problem lies in that the hash is calculated when the object is 
> not fully constructed. The hash value should be calculated as the last part 
> of the initialization process, as the hash should be dependent on the data 
> that defines the object. As the "..Algebra.__init__" is expected to be 
> placed at the beginning of the initialization code

Why? Is that a Python convention?

> , I think there should be 
> a separate method say "..Algebra._set_hash_" that is executed manually or 
> automatically at the end of the initialization process.

If it is automatic, then it will probably be at the end of the
initialisation process of Parent.__init__ - but then the problem would
not be solved, because you insist to call Parent.__init__ (indirectly
via ...Ring.__init__) before the initialisation of your object is
completed.

If it is manual and *has* to be done, then obviously a common
mistake would result, namely to forget initialising the hash.

Perhaps another idea, that I could easily implement: We could ensure
that calling ...Ring.__init__(..., category=False) would initialise the
ring except for the category framework. Then, the third solution of your
problem would be
    def __init__(self, i):
        CommutativeRing.__init__(self, i.base_ring(), category=False)
        self._ideal = i
        self._init_category_(CommutativeRings()) # or whatever is appropriate

Would that be acceptable to you?

Cheers,
Simon

-- 
To post to this group, send an email to [email protected]
To unsubscribe from this group, send an email to 
[email protected]
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to