Ticket #11935: trac_11935-weak_pickling_by_construction-review-ts.patch

File trac_11935-weak_pickling_by_construction-review-ts.patch, 12.6 KB (added by tscrim, 6 years ago)
  • sage/categories/category.py

    # HG changeset patch
    # User Travis Scrimshaw <tscrim@ucdavis.edur>
    # Date 1368759509 25200
    # Node ID 6df423f92134651196ec67a27d80e93744380ed6
    # Parent 77c87d9376e6c2eff25ab5aa625ccc14c9f62306
    #11935: review patch.
    
    diff --git a/sage/categories/category.py b/sage/categories/category.py
    a b class Category(UniqueRepresentation, Sag 
    436436
    437437        INPUT:
    438438
    439         - ``s`` -- A string giving the name of this category.
    440           If None, the name is determined from the name of the class.
     439        - ``s`` -- (Default: ``None``) A string giving the name of this
     440          category. If ``None``, the name is determined from the name of
     441          the class.
    441442
    442443        EXAMPLES::
    443444
    class Category(UniqueRepresentation, Sag 
    655656        ``category`` is a subclass of the parent class of ``self``.
    656657        This is most of the time a complete subcategory test.
    657658
    658         .. warning::
     659        .. WARNING::
    659660
    660661            This test is incomplete for categories in
    661662            :class:`CategoryWithParameters`, as introduced by
    662663            :trac:`11935`. This method is therefore overwritten by
    663664            :meth:`~sage.categories.category.CategoryWithParameters._subcategory_hook_`.
    664665
    665         EXAMPLE::
     666        EXAMPLES::
    666667
    667668            sage: Rings()._subcategory_hook_(Rings())
    668669            True
    class Category(UniqueRepresentation, Sag 
    10341035
    10351036    def _make_named_class(self, name, method_provider, cache=False, picklable=True):
    10361037        """
    1037         Construction of the parent/element/... class of self.
     1038        Construction of the parent/element/... class of ``self``.
    10381039
    10391040        INPUT:
    10401041
    1041         - ``name`` -- a string; the name of the class as an attribute of ``self``.
    1042           E.g. "parent_class"
     1042        - ``name`` -- a string; the name of the class as an attribute of
     1043          ``self``. E.g. "parent_class"
    10431044        - ``method_provider`` -- a string; the name of an attribute of
    10441045          ``self`` that provides methods for the new class (in
    10451046          addition to those coming from the super categories).
    10461047          E.g. "ParentMethods"
    1047         - ``cache`` -- a boolean or ``ignore_reduction`` (default: False)
     1048        - ``cache`` -- a boolean or ``ignore_reduction`` (default: ``False``)
    10481049          (passed down to dynamic_class; for internal use only)
    1049         - ``picklable`` -- a boolean (default: True)
     1050        - ``picklable`` -- a boolean (default: ``True``)
    10501051
    10511052        ASSUMPTION:
    10521053
    10531054        It is assumed that this method is only called from a lazy
    1054         attribute whose name coincides with the given ``name``
     1055        attribute whose name coincides with the given ``name``.
    10551056
    10561057        OUTPUT:
    10571058
    class Category(UniqueRepresentation, Sag 
    11051106
    11061107            sage: class A: pass
    11071108            sage: class BrokenCategory(Category):
    1108             ...       def super_categories(self): return []
    1109             ...       ParentMethods = 1
    1110             ...       class ElementMethods(A):
    1111             ...           pass
    1112             ...       class MorphismMethods(object):
    1113             ...           pass
     1109            ....:     def super_categories(self): return []
     1110            ....:     ParentMethods = 1
     1111            ....:     class ElementMethods(A):
     1112            ....:         pass
     1113            ....:     class MorphismMethods(object):
     1114            ....:         pass
    11141115            sage: C = BrokenCategory()
    11151116            sage: C._make_named_class("parent_class",   "ParentMethods")
    11161117            Traceback (most recent call last):
    class HomCategory(Category): 
    17481749
    17491750class CategoryWithParameters(Category):
    17501751    """
    1751     A parametrized category whose parent/element classes depend only on its super categories
     1752    A parametrized category whose parent/element classes depend only on
     1753    its super categories.
    17521754
    1753     Many categories in Sage are parametrized, like ``C=Algebras(K)``
     1755    Many categories in Sage are parametrized, like ``C = Algebras(K)``
    17541756    which takes a base ring as parameter. In many cases, however, the
    17551757    operations provided by ``C`` in the parent class and element class
    17561758    depend only on the super categories of ``C``. For example, the
    class CategoryWithParameters(Category): 
    17771779        True
    17781780        sage: C1.parent_class is C3.parent_class
    17791781        False
    1780 
    17811782    """
    17821783    def _make_named_class(self, name, method_provider, cache = False, **options):
    17831784        """
    class CategoryWithParameters(Category): 
    17851786
    17861787        INPUT:
    17871788
    1788         - ``name`` -- a string; the name of the class as an attribute of ``self``
     1789        - ``name`` -- a string; the name of the class as an attribute
     1790          of ``self``
    17891791        - ``method_provider`` -- a string; the name of an attribute of
    17901792          ``self`` that provides methods for the new class (in
    1791           addition to what comes from the super categories).
     1793          addition to what comes from the super categories)
    17921794
    17931795        ASSUMPTION:
    17941796
    17951797        It is assumed that this method is only called from a lazy
    1796         attribute whose name coincides with the given ``name``
     1798        attribute whose name coincides with the given ``name``.
    17971799
    17981800        OUTPUT:
    17991801
    18001802        A dynamic class that has the corresponding named classes of
    18011803        the super categories of ``self`` as bases and contains the
    1802         methods provided by ``getattr(self,method_provider)``.
     1804        methods provided by ``getattr(self, method_provider)``.
    18031805
    18041806        .. NOTE::
    18051807
    class CategoryWithParameters(Category): 
    18101812            classes across closely related categories providing the
    18111813            same code to their parents, elements and so on.
    18121814
    1813         EXAMPLES::
     1815        EXAMPLES:
    18141816
    1815         The categories of bimodules over the fields ``CC`` or ``QQ``
     1817        The categories of bimodules over the fields ``CC`` or ``RR``
    18161818        provide the same methods to their parents and elements::
    18171819
    18181820            sage: Bimodules(ZZ,RR).parent_class is Bimodules(ZZ,RDF).parent_class #indirect doctest
    class CategoryWithParameters(Category): 
    18281830            sage: Modules(GF(3)).element_class is Modules(ZZ).element_class
    18291831            False
    18301832
    1831         One could possibly share those classes, but this is not
    1832         currently the case::
     1833        For a more subtle example, one could possibly share the classes for
     1834        ``GF(3)`` and ``GF(2^3, 'x')``, but this is not currently the case::
    18331835
    18341836            sage: Modules(GF(3)).parent_class is Modules(GF(2^3,'x')).parent_class
    18351837            False
    class CategoryWithParameters(Category): 
    18411843            sage: GF(2^3,'x').category()
    18421844            Category of finite fields
    18431845
     1846        Similarly for ``QQ`` and ``RR``::
     1847
     1848            sage: QQ.category()
     1849            Category of quotient fields
     1850            sage: RR.category()
     1851            Category of fields
     1852            sage: Modules(QQ).parent_class is Modules(RR).parent_class
     1853            False
     1854
    18441855        Some other cases where one could potentially share those classes::
    18451856
    18461857            sage: Modules(GF(3),dispatch=False).parent_class  is Modules(ZZ).parent_class
    class CategoryWithParameters(Category): 
    18791890
    18801891        INPUT:
    18811892
    1882         - ``name`` -- a string; the name of the class as an attribute of ``self``
     1893        - ``name`` -- a string; the name of the class as an attribute
     1894          of ``self``
    18831895
    18841896        .. SEEALSO::
    18851897
    class CategoryWithParameters(Category): 
    19131925
    19141926    def _subcategory_hook_(self, C):
    19151927        """
    1916         A quick but partial test whether ``C`` is a subcategory of ``self``
     1928        A quick but partial test whether ``C`` is a subcategory of ``self``.
    19171929
    19181930        INPUT:
    19191931
    class CategoryWithParameters(Category): 
    19211933
    19221934        OUTPUT:
    19231935
    1924         - ``False``, if ``C.parent_class`` is not a subclass of
    1925           ``self.parent_class``, and :obj:`~sage.misc.unknown.Unknown`
    1926           otherwise.
     1936        ``False``, if ``C.parent_class`` is not a subclass of
     1937        ``self.parent_class``, and :obj:`~sage.misc.unknown.Unknown`
     1938        otherwise.
    19271939
    19281940        EXAMPLES::
    19291941
    class JoinCategory(CategoryWithParameter 
    19671979        Join of Category of euclidean domains and Category of commutative algebras over Finite Field of size 3
    19681980        sage: type(GF(3)['x']) is type(GF(5)['z'])
    19691981        True
    1970 
    19711982    """
    19721983
    19731984    def __init__(self, super_categories, **kwds):
    class JoinCategory(CategoryWithParameter 
    20042015
    20052016        Since :trac:`11935`, the element/parent classes of a join
    20062017        category over base only depend on the element/parent class of
    2007         its super categories
     2018        its super categories.
    20082019
    20092020        .. SEEALSO::
    20102021
    class JoinCategory(CategoryWithParameter 
    20592070
    20602071    def is_subcategory(self, C):
    20612072        """
    2062         Tell whether this join category is subcategory of another category `C`.
     2073        Check whether this join category is subcategory of another
     2074        category ``C``.
    20632075
    20642076        EXAMPLES::
    20652077
    20662078            sage: Category.join([Rings(),Modules(QQ)]).is_subcategory(Category.join([Rngs(),Bimodules(QQ,QQ)]))
    20672079            True
    2068 
    20692080        """
    20702081        if C is self:
    20712082            return True
  • sage/categories/category_types.py

    diff --git a/sage/categories/category_types.py b/sage/categories/category_types.py
    a b class Category_over_base(CategoryWithPar 
    263263
    264264    def _subcategory_hook_(self, C):
    265265        """
    266         A quick test whether a category `C` may be subcategory of this category.
     266        A quick test whether a category ``C`` may be subcategory of
     267        this category.
    267268
    268269        INPUT:
    269270
    270         - `C` `` a category (type not tested)
     271        - ``C`` -- a category (type not tested)
    271272
    272273        OUTPUT:
    273274
    274         a boolean if it is certain that `C` is (or is not) a
     275        A boolean if it is certain that ``C`` is (or is not) a
    275276        subcategory of self. :obj:`~sage.misc.unknown.Unknown`
    276277        otherwise.
    277278
  • sage/structure/dynamic_class.py

    diff --git a/sage/structure/dynamic_class.py b/sage/structure/dynamic_class.py
    a b def dynamic_class(name, bases, cls = Non 
    126126
    127127    - ``name`` -- a string
    128128    - ``bases`` -- a tuple of classes
    129     - ``cls`` -- a class or None
    130     - ``reduction`` -- a tuple or None
    131     - ``doccls`` -- a class or None
    132     - ``prepend_cls_bases`` -- a boolean (default: True)
    133     - ``cache`` -- a boolean or "ignore_reduction" (default: True)
     129    - ``cls`` -- a class or ``None``
     130    - ``reduction`` -- a tuple or ``None``
     131    - ``doccls`` -- a class or ``None``
     132    - ``prepend_cls_bases`` -- a boolean (default: ``True``)
     133    - ``cache`` -- a boolean or ``"ignore_reduction"`` (default: ``True``)
    134134
    135135    Constructs dynamically a new class ``C`` with name ``name``, and
    136136    bases ``bases``. If ``cls`` is provided, then its methods will be
    137137    inserted into ``C``, and its bases will be prepended to ``bases``
    138     (unless ``prepend_cls_bases`` is False).
     138    (unless ``prepend_cls_bases`` is ``False``).
    139139
    140140    The module, documentation and source instrospection is taken from
    141141    ``doccls``, or ``cls`` if ``doccls`` is ``None``, or ``bases[0]``
    def dynamic_class(name, bases, cls = Non 
    145145    The constructed class can safely be pickled (assuming the
    146146    arguments themselves can).
    147147
    148     Unless ``cache`` is False, the result is cached, ensuring unique
     148    Unless ``cache`` is ``False``, the result is cached, ensuring unique
    149149    representation of dynamic classes.
    150150
    151151    See :mod:`sage.structure.dynamic_class` for a discussion of the
    def dynamic_class(name, bases, cls = Non 
    154154    EXAMPLES:
    155155
    156156    To setup the stage, we create a class Foo with some methods,
    157     cached methods, and lazy_attributes, and a class Bar::
     157    cached methods, and lazy attributes, and a class Bar::
    158158   
    159159        sage: from sage.misc.lazy_attribute import lazy_attribute
    160160        sage: from sage.misc.cachefunc import cached_function
    def dynamic_class(name, bases, cls = Non 
    231231
    232232    .. RUBRIC:: Caching
    233233
    234     By default, the built class is cached:
     234    By default, the built class is cached::
    235235
    236236         sage: dynamic_class("FooBar", (Bar,), Foo) is FooBar
    237237         True
    def dynamic_class(name, bases, cls = Non 
    263263        sage: dynamic_class("BarFoo", (Foo,), Bar, reduction = (str, (2,)), cache="ignore_reduction") is BarFoo
    264264        True
    265265
    266     In particular, the reduction used is that provided upon creating the first class::
     266    In particular, the reduction used is that provided upon creating the
     267    first class::
    267268
    268269        sage: dynamic_class("BarFoo", (Foo,), Bar, reduction = (str, (2,)), cache="ignore_reduction")._reduction
    269270        (<type 'str'>, (3,))