GeezerVison is showing github.com — Tests for what kind of an element something is should test the parent · Issue #803 · sagemath/sage
Tests for what kind of an element something is should test the parent #803Description
Calls like:
algebras/algebra_order.py: elif isinstance(x, RingElement) and x in self.base_ring():
algebras/algebra_order_ideal.py: elif isinstance(x, RingElement) and x in self.base_ring():
algebras/free_algebra_quotient_element.py: elif isinstance(x, RingElement) and not isinstance(x, AlgebraElement) and x in R:
rings/infinity.py: elif isinstance(x, RingElement) or isinstance(x, (int,long,float,complex)):
rings/infinity.py: elif isinstance(x, RingElement):
should actually be checking to see if the parents are of the appropriate type. The element types are not always reliable: parents more accurately reflect the mathematical structure (mostly because they can have multiple inheritance).
There may be more instances in addition to those above (I just ran search_src("isinstance(x, RingElement)"))
Component: basic arithmetic
Reviewer: Vincent Delecroix
Issue created by migration from https://trac.sagemath.org/ticket/803 Activitywilliamstein commented on Feb 25, 2008 comment:1
I'm dubious:
My immediate thought when looking at #803 is that it is the wrong
idea in the first place. If I had looked at #803 before
now I would have considered marking it "invalid".
There are individual instances that involve "isinstance" that were
perhaps badly written. E.g., the first example:
elif isinstance(x, RingElement) and x in self.base_ring():
return True
Here I think the original author (David Kohel) may have written
this at a time when "in" could raise an exception if x isn't
a RingElement. That's no longer the case, so in this particular
example the right fix is I think to put:
elif x in self.base_ring():
return True
In probably hundreds of other cases the use of isinstance in
Sage is exactly right. In some cases it could be improved,
but how will depend in each case on understanding the code. videlec commented on Apr 14, 2015 Reviewer: Vincent Delecroix
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|