Ticket #11342: trac11342_test_parent_on_getattr.patch

File trac11342_test_parent_on_getattr.patch, 1.2 KB (added by SimonKing, 9 years ago)

Test whether self._parent is None, before requestin self._parent._category

  • sage/structure/element.pyx

    # HG changeset patch
    # User Simon King <simon.king@uni-jena.de>
    # Date 1314212534 -7200
    # Node ID fe7ab69da4f4e134f4fb4c14d254c9ee968c2246
    # Parent  452a12e776771e31d2ed68182e7a2355e60dbcfd
    #11342: Test whether the parent of an element is None, before requesting its category
    
    diff --git a/sage/structure/element.pyx b/sage/structure/element.pyx
    a b  
    323323            AttributeError: 'sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint' object has no attribute '__foo'
    324324
    325325        """
    326         if (name.startswith('__') and not name.endswith('_')) or self._parent._category is None:
     326        if (name.startswith('__') and not name.endswith('_')):
    327327            raise AttributeError, AttributeErrorMessage(self, name)
    328         return getattr_from_other_class(self, self._parent._category.element_class, name)
     328        cdef Parent P = self._parent or self.parent()
     329        if P is None or P._category is None:
     330            raise AttributeError, AttributeErrorMessage(self, name)
     331        return getattr_from_other_class(self, P._category.element_class, name)
    329332
    330333    def __dir__(self):
    331334        """