#11943: The category graph should comply with Python's method resolution order
---------------------------+------------------------------------------------
   Reporter:  SimonKing    |          Owner:  nthiery                           
     
       Type:  enhancement  |         Status:  needs_work                        
     
   Priority:  major        |      Milestone:  sage-4.8                          
     
  Component:  categories   |       Keywords:  category graph, method resolution 
order
Work_issues:               |       Upstream:  N/A                               
     
   Reviewer:               |         Author:  Simon King                        
     
     Merged:               |   Dependencies:  #11900                            
     
---------------------------+------------------------------------------------

Comment(by nthiery):

 Replying to [comment:15 SimonKing]:
 > I found another detail that may fit here: `Category.is_subcategory`
 contains the lines
 > {{{
 >         assert(isinstance(c, Category))
 >         if isinstance(self, JoinCategory):
 >             for cat in self._super_categories:
 >                 if cat.is_subcategory(c):
 >                     return True
 >             return False
 > }}}
 > First, I don't see why it should be needed to assert that c is a
 Category. It seems like a waste of time to me.

 As for any reasonable programming language, Python allows to
 completely disable assertion tests, to encourage the programmer to put
 more safety guards and write programmatically his
 preconditions/assertions/..., knowing that in production there won't
 be any penalty.  Alas, this can't be done on the fly like in MuPAD for
 switching between debugging and full speed computation modes inside a
 given session (a feature I loved). Still this can be achieved in
 principle on a new session by passing -O to the Python
 interpreter. Maybe we should add this option to the Sage script
 itself.

 In that particular case, I guess I once met a bug where something was
 passed to is_subcategory which was not a category, so I felt safer
 with the assertion test.

 > Secondly, the loop does nothing more than to test the cat is in the
 > set of super categories of self. So, it can be safely erased. And it
 > is a lot faster. ...
 > So, my next patch version will remove these lines, provided that doc
 tests pass.

 I don't remember anymore why I did a special case for join categories,
 so +1.

 Cheers,
                         Nicolas

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11943#comment:18>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to