You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tests for what kind of an element something is should test the parent #803
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)"))
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.
Activity
williamstein commentedon Feb 25, 2008
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:
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:
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 commentedon Apr 14, 2015
Reviewer: Vincent Delecroix
sagemathgh-43136: build(deps): bump softprops/action-gh-release from …