#11791: Introspection for interactively defined classes with metaclass
---------------------------+------------------------------------------------
   Reporter:  SimonKing    |          Owner:  jason                             
      
       Type:  enhancement  |         Status:  needs_review                      
      
   Priority:  major        |      Milestone:  sage-4.7.2                        
      
  Component:  misc         |       Keywords:  introspection, cython, dynamic 
metaclass
Work_issues:               |       Upstream:  N/A                               
      
   Reviewer:               |         Author:  Simon King                        
      
     Merged:               |   Dependencies:  #11298, #11768, #11734            
      
---------------------------+------------------------------------------------
Changes (by SimonKing):

  * status:  new => needs_review


Comment:

 The attached patch seems to solve the problem. From the doctests:
 {{{
         sage: cython_code = [
         ... 'from sage.structure.dynamic_class import dynamic_class',
         ... 'from sage.all import cached_function',
         ... 'MyMetaclass =
 dynamic_class("MyMetaclass",(ClasscallMetaclass,))',
         ... 'class Bar2:',
         ... '    __metaclass__ = MyMetaclass',
         ... '    @cached_function',
         ... '    def __classcall__(cls, R):',
         ... '        return type.__call__(cls, R)',
         ... '    def __init__(self,R):',
         ... '        self.R = R',
         ... '    def __repr__(self):',
         ... '        return "[%s]"%self.R',
         ... '    def __hash__(self):',
         ... '        print "computing the hash"',
         ... '        return int(12345)']
         sage: cython('\n'.join(cython_code))
         sage: print ''.join(sage_getsourcelines(Bar2)[0])
         class Bar2:
             __metaclass__ = MyMetaclass
             @cached_function
             def __classcall__(cls, R):
                 return type.__call__(cls, R)
             def __init__(self,R):
                 self.R = R
             def __repr__(self):
                 return "[%s]"%self.R
             def __hash__(self):
                 print "computing the hash"
                 return int(12345)
 }}}

 The tests of `sage.misc.sageinspect` pass with the patch. I did not try
 full tests yet, but I think it could already be reviewed.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11791#comment:1>
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