#14912: UniqueRepresentation tutorial could use more love
--------------------------------------------+------------------------------
       Reporter:  darij                     |        Owner:
           Type:  defect                    |       Status:  needs_review
       Priority:  major                     |    Milestone:  sage-5.13
      Component:  documentation             |   Resolution:
       Keywords:  documentation, structure  |    Merged in:
        Authors:  Simon King                |    Reviewers:  Darij Grinberg
Report Upstream:  N/A                       |  Work issues:
         Branch:                            |       Commit:
   Dependencies:                            |     Stopgaps:
--------------------------------------------+------------------------------

Comment (by SimonKing):

 Replying to [comment:23 darij]:
 > Sorry for letting this slip off my to-do list!

 Same here...

 > I'm pretty sure that I've understood the important points of the doc now
 except for some that concern pickling (I don't know how it works and
 frankly I didn't plan on learning that). I'd feel better if I knew what
 exactly {{{__classcall__}}} does and (as I said) how it is distinguished
 from {{{__new__}}} and {{{__init__}}} (and if it calls them, in which
 order), but that might as well be a different patch.

 In a nutshell: If `C` is a class with `ClasscallMetaclass`, then
 `__classcall__` (or `__classcall_private__`) is what is executed when you
 do `C(*args, **kwds)`.

 Your `__classcall__` can do ''anything''. Really. It could return an
 instance of `C`, but it could also return something totally different.

 Consequence: `__new__` or `__init__` are ''only'' called if you did not
 forget to call them inside of your `__classcall__`. If you look at what
 `CachedRepresentation.__classcall__` does, you see that indeed `__new__`
 and `__init__` are called explicitly.

 > I'd like more details on this:
 > {{{
 > 104       In addition, it is required that a unique factory instance is
 provided
 > 105       with a name that allows to find its definition.
 > }}}
 > I assume this refers to the string parameter, e. g., in {{{F =
 MyFactory("__main__.F")}}};

 Exactly.

 > but what kind of path should it contain if it is to be used somewhere in
 a .py file rather than in a doctest? Just {{{F = MyFactory("F")}}} ?

 It is exactly as it is stated: A name is needed that allows to find the
 factory's definition. Hence, if you put `F` into the global name space,
 then `F = MyFactory("F")` is fine. If `F` is in a module `sage.foo.bar`,
 then it is `F = MyFactory("sage.foo.bar.F")`.

 > What if it is defined inside a class?

 If the class is `sage.bar.foo.MyClass` and you want to use a factory for
 the attribute `F` of this class, then I guess it is `F =
 MyFactory("sage.bar.foo.MyClass.F"). Not tested, though.

 > Not sure about this:
 > {{{
 > And
 >       408     with a factory, it is possible to create the resulting
 instance by arguments
 >       409     that are different from the key used for caching.
 > }}}
 > Doesn't that also work with CachedRepresentation if one preprocesses by
 declaring {{{__classcall_private__}}}?

 Yes. This could be clarified.

--
Ticket URL: <http://trac.sagemath.org/ticket/14912#comment:25>
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.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to