Ticket #8250: trac_8250-classcall-classget-review-2.patch

File trac_8250-classcall-classget-review-2.patch, 3.8 KB (added by hivert, 10 years ago)
  • doc/en/reference/misc.rst

    # HG changeset patch
    # User Florent Hivert <Florent.Hivert@univ-rouen.fr>
    # Date 1266075432 -3600
    # Node ID 7fc2c455fdc1b230f6ed52c26f293485dab73b71
    # Parent  f5eba38970c2e43a49a713168fc5615ed8882177
    #8250: Improved Doc + Added (ClassCall|Nested)Metaclass to the reference manual.
    
    diff --git a/doc/en/reference/misc.rst b/doc/en/reference/misc.rst
    a b Miscellaneous 
    3030   sage/misc/random_testing
    3131   sage/misc/sagedoc
    3232   sage/rings/arith
     33   sage/misc/nested_class
     34   sage/misc/classcall_metaclass
  • sage/misc/classcall_metaclass.py

    diff --git a/sage/misc/classcall_metaclass.py b/sage/misc/classcall_metaclass.py
    a b  
    11r"""
    2 ClasscallMetaclass
     2Special Methods for Classes.
    33"""
    44#*****************************************************************************
    55#  Copyright (C) 2009    Nicolas M. Thiery <nthiery at users.sf.net>
    class ClasscallMetaclass(NestedClassMeta 
    3131     - ``.__classget__`` for customizing the binding behavior in
    3232       ``foo.cls`` (analogue of ``.__get__``).
    3333
    34     See the documentation of :meth:`.__classcall__`` and of
    35     :meth:`.__classget`` for the description of the respective protocol.
     34    See the documentation of :meth:`.__call__`` and of
     35    :meth:`.__get__`` for the description of the respective protocols.
    3636
    3737    TODO: find a good name for this metaclass.
    3838
    class ClasscallMetaclass(NestedClassMeta 
    6868        ``obj.Inner(...)`` is equivalent to ``Outer.Inner(obj, ...)``::
    6969
    7070            sage: import functools
     71            sage: from sage.misc.nested_class import NestedClassMetaclass
    7172            sage: from sage.misc.classcall_metaclass import ClasscallMetaclass
    7273            sage: class Outer:
     74            ...       __metaclass__ = NestedClassMetaclass # workaround for python pickling bug
     75            ...
    7376            ...       class Inner(object):
    7477            ...           __metaclass__ = ClasscallMetaclass
    7578            ...           @staticmethod
    class ClasscallMetaclass(NestedClassMeta 
    8386            ...               self.instance = instance
    8487            sage: obj = Outer()
    8588            sage: bar = obj.Inner()
    86             calling __classget__(<class '__main__.Inner'>, <__main__.Outer instance at 0x...>, __main__.Outer)
     89            calling __classget__(<class '__main__.Outer.Inner'>, <__main__.Outer object at 0x...>, <class '__main__.Outer'>)
    8790            sage: bar.instance == obj
    8891            True
    8992
    9093        Calling ``Outer.Inner`` returns the (unbinded) class as usual::
    9194
    9295            sage: Inner = Outer.Inner
    93             calling __classget__(<class '__main__.Inner'>, None, __main__.Outer)
     96            calling __classget__(<class '__main__.Outer.Inner'>, None, <class '__main__.Outer'>)
    9497            sage: Inner
    95             <class '__main__.Inner'>
     98            <class '__main__.Outer.Inner'>
    9699            sage: type(bar) is Inner
    97100            True
    98101
    class ClasscallMetaclass(NestedClassMeta 
    101104        ..warning:: calling ``obj.Inner`` does no longer return a class::
    102105
    103106            sage: bind = obj.Inner
    104             calling __classget__(<class '__main__.Inner'>, <__main__.Outer instance at ...>, __main__.Outer)
     107            calling __classget__(<class '__main__.Outer.Inner'>, <__main__.Outer object at 0x...>, <class '__main__.Outer'>)
    105108            sage: bind
    106109            <functools.partial object at 0x...>
    107110        """
  • sage/misc/nested_class.py

    diff --git a/sage/misc/nested_class.py b/sage/misc/nested_class.py
    a b  
    11"""
     2Fixing Pickle for Nested Classes.
     3
    24As of Python 2.6, names for nested classes are set by Python in  a
    35way which is incompatible with the pickling of such classes (pickling by name)::
    46