Ticket #14486: trac_14486_set_coercion.patch

File trac_14486_set_coercion.patch, 1.4 KB (added by vbraun, 9 years ago)

Updated patch

  • sage/sets/set.py

    # HG changeset patch
    # User Volker Braun <vbraun.name@gmail.com>
    # Date 1366887998 -3600
    # Node ID cb9735f1d2ebc9466b2c06727ae3d1d296e7b345
    # Parent  6d0d6381e4542f088f4638c7a6bcd12e83aa2fa4
    Disallow conversion of 0 into Set_object
    
    diff --git a/sage/sets/set.py b/sage/sets/set.py
    a b  
    193193
    194194        sage: latex(Set(ZZ))
    195195        \Bold{Z}
     196
     197    TESTS::
     198
     199        sage: 0 == Set([1]), Set([1]) == 0
     200        (False, False)
     201        sage: 1 == Set([0]), Set([0]) == 1
     202        (False, False)
    196203    """
    197204    def __init__(self, X):
    198205        """
     
    205212       
    206213            sage: type(Set(QQ))
    207214            <class 'sage.sets.set.Set_object_with_category'>
     215
     216        TESTS::
     217
     218            sage: _a, _b = get_coercion_model().canonical_coercion(Set([0]), 0)
     219            Traceback (most recent call last):
     220            ...
     221            TypeError: no common canonical parent for objects with parents:
     222            '<class 'sage.sets.set.Set_object_enumerated_with_category'>'
     223            and 'Integer Ring'
    208224        """
     225        from sage.rings.integer import is_Integer
     226        if isinstance(X, (int,long)) or is_Integer(X): 
     227            # The coercion model will try to call Set_object(0)
     228            raise ValueError('underlying object cannot be an integer')
    209229        Parent.__init__(self, category=Sets())
    210230        self.__object = X
    211231