Ticket #13811: lazyfamcopy.patch

File lazyfamcopy.patch, 1.7 KB (added by cnassau, 8 years ago)

A patch for this problem

  • sage/sets/family.py

    # HG changeset patch
    # User Christian Nassau <nassau@nullhomotopie.de>
    # Date 1354970339 -3600
    # Node ID 092fd8158d79a9ed9193e09d9dfeed9363ef0025
    # Parent  f4cbda7c354e4f5c27adb054b495dcafce5d5db1
    make sure lazy families can be copied (#13811)
    
    diff --git a/sage/sets/family.py b/sage/sets/family.py
    a b  
    821821            sage: l[1] = 18
    822822            sage: f
    823823            Lazy family (<lambda>(i))_{i in [3, 4, 7]}
     824
     825        Make sure LazyFamilies support shallow copies, even if they cannot be pickled::
     826
     827            sage: def unpicklableFamily():
     828            ...       x = 10
     829            ...       return LazyFamily([1,2,3], lambda n: x*n)
     830            sage: f = unpicklableFamily()
     831            sage: f._test_pickling()
     832            Traceback (most recent call last):
     833            ...
     834            ValueError: Cannot pickle code objects from closures
     835            sage: list(copy(f))
     836            [10, 20, 30]
     837
    824838        """
    825839        from sage.combinat.combinat import CombinatorialClass # workaround #12482
    826840
     
    840854        self.set = copy(set)
    841855        self.function = function
    842856
     857    def __copy__(self):
     858        """
     859        Create a shallow copy of ``self``.
     860
     861        TESTS::
     862
     863            sage: from sage.sets.family import LazyFamily
     864            sage: from copy import copy
     865            sage: fun = lambda i: 2*i
     866            sage: f = LazyFamily([3,4,7], fun)
     867            sage: g = copy(f)
     868            sage: f is g
     869            False
     870            sage: list(f) == list(g)
     871            True
     872        """
     873        return LazyFamily(self.set,self.function)
    843874
    844875    def __eq__(self, other):
    845876        """