@@ -1673,12 +1673,29 @@ def set_expr(self, coord_expression, chart=None):
16731673 sage: f._express # the (u,v) expression has been lost:
16741674 {Chart (M, (x, y)): 3*y}
16751675
1676+ Since zero and one are special elements, their components cannot be
1677+ changed::
1678+
1679+ sage: z = M.zero_scalar_field()
1680+ sage: z.set_expr(3*y)
1681+ Traceback (most recent call last):
1682+ ...
1683+ AssertionError: the components of the element zero cannot be changed
1684+ sage: one = M.one_scalar_field()
1685+ sage: one.set_expr(3*y)
1686+ Traceback (most recent call last):
1687+ ...
1688+ AssertionError: the components of the element 1 cannot be changed
1689+
16761690 """
1691+ if self is self .parent ().one () or self is self .parent ().zero ():
1692+ raise AssertionError ("the components of the element "
1693+ "{} cannot be changed" .format (self ._name ))
16771694 if chart is None :
16781695 chart = self ._domain ._def_chart
1679- self ._is_zero = False # a priori
16801696 self ._express .clear ()
16811697 self ._express [chart ] = chart .function (coord_expression )
1698+ self ._is_zero = False # a priori
16821699 self ._del_derived ()
16831700
16841701 def add_expr (self , coord_expression , chart = None ):
@@ -1718,7 +1735,24 @@ def add_expr(self, coord_expression, chart=None):
17181735 sage: f._express # random (dict. output); f has now 2 expressions:
17191736 {Chart (M, (x, y)): 3*y, Chart (M, (u, v)): cos(u) - sin(v)}
17201737
1738+ Since zero and one are special elements, their components cannot be
1739+ changed::
1740+
1741+ sage: z = M.zero_scalar_field()
1742+ sage: z.add_expr(cos(u)-sin(v), c_uv)
1743+ Traceback (most recent call last):
1744+ ...
1745+ AssertionError: the components of the element zero cannot be changed
1746+ sage: one = M.one_scalar_field()
1747+ sage: one.add_expr(cos(u)-sin(v), c_uv)
1748+ Traceback (most recent call last):
1749+ ...
1750+ AssertionError: the components of the element 1 cannot be changed
1751+
17211752 """
1753+ if self is self .parent ().one () or self is self .parent ().zero ():
1754+ raise AssertionError ("the components of the element "
1755+ "{} cannot be changed" .format (self ._name ))
17221756 if chart is None :
17231757 chart = self ._domain ._def_chart
17241758 self ._express [chart ] = chart .function (coord_expression )
0 commit comments