#14167: UniqueRepresentation using default arguments
----------------------------------------------------------+-----------------
       Reporter:  SimonKing                               |         Owner:  
jason       
           Type:  enhancement                             |        Status:  
needs_review
       Priority:  major                                   |     Milestone:  
sage-5.8    
      Component:  misc                                    |    Resolution:      
        
       Keywords:  UniqueRepresentation default arguments  |   Work issues:      
        
Report Upstream:  N/A                                     |     Reviewers:      
        
        Authors:  Simon King                              |     Merged in:      
        
   Dependencies:  #14054                                  |      Stopgaps:      
        
----------------------------------------------------------+-----------------
Changes (by SimonKing):

  * status:  new => needs_review


Comment:

 This ticket builds upon #14054, namely it uses the distinction of
 `UniqueRepresentation` and `CachedRepresentation`.

 The idea to make default arguments work is as follows. Let C be a subclass
 of `CachedRepresentation`, and assume that it overrides `__init__`.

 - I changed `weak_chached_function`, so that a function can be passed as
 an optional parameter from which the argspec is taken.

 - `CachedRepresentation.__classcall__` used to be a cached function,
 stored as an attribute of `CachedRepresentation`. This will still be the
 case. Of course, `CachedRepresentation` does not know about `C.__init__`.
 Hence, `CachedRepresentation.__classcall__` has no default arguments.

 - However, when the first instance of C is created, then
 `CachedRepresentation.__classcall__` is called with C. In that moment,
 `C.__init__` is available. `CachedRepresentation.__classcall__` will then
 create a new weak_cached_function that uses the argspec of `C.__init__`.
 This new weak_cached_function will override the cdef attribute
 `C.classcall`, provided that `C.classcall` is the same as
 `CachedRepresentation.__classcall__` (hence, a custom `__classcall__` or
 `__classcall_private__` will be respected). The new weak_cached_function
 creates, caches and returns the first instance of C.

 - When the second instance of C is created, the new weak_cached_function
 is called, and `CachedRepresentation.__classcall__` is not involved any
 more.

 - Since only `C.classcall` is overridden, but not `C.__classcall__`, it is
 no problem to subclass C: If D is a subclass of C, then the first instance
 of D will be created in `CachedRepresentation.__classcall__`, which will
 override D.classcall, but does not affect C.classcall.

 __Smaller changes__

 - `ClasscallMetaclass` gets methods `_get_caller_` and
 `_overload_caller_`, so that one can retrieve or overload C.classcall from
 a Python module.
 - `WeakCachedFunction.__init__` gets a new optional argument
 `argspec_from`, which is supposed to be a function from which the cached
 function gets its defaults. `argspec_from` is passed down to the weak
 cached function's "_argument_fixer`, whose job it is to take care of
 default arguments.
 - In `sage.misc.superseded._check_trac_number`, I remove the import of
 `is_Integer`. Namely, at least with some preliminary version of the patch,
 this import used to crash Sage during startup. What we want to know in
 this function is whether the given trac number is a positive integer. I
 suggest to do a very similar thing to the default containment test of
 parents: trac_number is an integer if `int(trac_number)==trac_number`
 returns True and does not raise an error.
 - I use `.. TODO::` and similar directives in a couple of cases.

 Needs review, then!

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/14167#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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to