Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit d97d665

Browse files
committed
Fix coercion of scalar fields in modules of differential forms (trac #27658)
1 parent 165d450 commit d97d665

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/sage/manifolds/differentiable/diff_form_module.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,28 @@
2424
- [Lee2013]_
2525
2626
"""
27-
#******************************************************************************
27+
# *****************************************************************************
2828
# Copyright (C) 2015 Eric Gourgoulhon <[email protected]>
2929
# Copyright (C) 2016 Travis Scrimshaw <[email protected]>
3030
#
3131
# Distributed under the terms of the GNU General Public License (GPL)
3232
# as published by the Free Software Foundation; either version 2 of
3333
# the License, or (at your option) any later version.
34-
# http://www.gnu.org/licenses/
35-
#******************************************************************************
34+
# https://www.gnu.org/licenses/
35+
# *****************************************************************************
3636

3737
from sage.misc.cachefunc import cached_method
3838
from sage.structure.unique_representation import UniqueRepresentation
3939
from sage.structure.parent import Parent
4040
from sage.categories.modules import Modules
4141
from sage.rings.integer import Integer
4242
from sage.tensor.modules.ext_pow_free_module import ExtPowerDualFreeModule
43+
from sage.manifolds.scalarfield import ScalarField
4344
from sage.manifolds.differentiable.diff_form import DiffForm, DiffFormParal
4445
from sage.manifolds.differentiable.tensorfield import TensorField
4546
from sage.manifolds.differentiable.tensorfield_paral import TensorFieldParal
4647

48+
4749
class DiffFormModule(UniqueRepresentation, Parent):
4850
r"""
4951
Module of differential forms of a given degree `p` (`p`-forms) along a
@@ -354,6 +356,10 @@ def _element_constructor_(self, comp=[], frame=None, name=None,
354356
else:
355357
raise TypeError("cannot convert the {} ".format(tensor) +
356358
"to an element of {}".format(self))
359+
if isinstance(comp, ScalarField):
360+
# since the degree of self is >= 1, we cannot coerce scalar fields:
361+
raise TypeError("cannot convert the {} ".format(comp) +
362+
"to an element of {}".format(self))
357363
# standard construction
358364
resu = self.element_class(self._vmodule, self._degree, name=name,
359365
latex_name=latex_name)
@@ -545,7 +551,7 @@ def degree(self):
545551
"""
546552
return self._degree
547553

548-
#******************************************************************************
554+
# *****************************************************************************
549555

550556
class DiffFormFreeModule(ExtPowerDualFreeModule):
551557
r"""
@@ -790,6 +796,12 @@ def _element_constructor_(self, comp=[], frame=None, name=None,
790796
sage: A(0) is A.zero()
791797
True
792798
799+
Check that #27658 is fixed::
800+
801+
sage: f = M.scalar_field(x)
802+
sage: f in A
803+
False
804+
793805
"""
794806
if isinstance(comp, (int, Integer)) and comp == 0:
795807
return self.zero()
@@ -815,6 +827,10 @@ def _element_constructor_(self, comp=[], frame=None, name=None,
815827
else:
816828
raise TypeError("cannot convert the {} ".format(tensor) +
817829
"to an element of {}".format(self))
830+
if isinstance(comp, ScalarField):
831+
# since the degree of self is >= 1, we cannot coerce scalar fields:
832+
raise TypeError("cannot convert the {} ".format(comp) +
833+
"to an element of {}".format(self))
818834
resu = self.element_class(self._fmodule, self._degree, name=name,
819835
latex_name=latex_name)
820836
if comp != []:

0 commit comments

Comments
 (0)