Skip to content

Commit 6b20467

Browse files
author
Matthias Koeppe
committed
MPolynomial_element._test_subs: Check that partial substitution by elements from another ring raises an exception
1 parent 98093fe commit 6b20467

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/sage/rings/polynomial/multi_polynomial_element.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,14 +402,21 @@ def _test_subs(self, tester=None, **options):
402402
# with elements of another ring
403403
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
404404
other = PolynomialRing(self.parent().base_ring(), 'other', len(gens))
405-
d = {str(gen): other_gen for gen, other_gen in zip(gens, other.gens())}
405+
other_gens = other.gens()
406+
d = {str(gen): other_gen for gen, other_gen in zip(gens, other_gens)}
406407
tester.assertEqual(self.subs(**d).parent(), other)
407408

408409
if len(gens) > 1:
409410
# substituting one variable (in a polynomial ring with variables) with 0
410411
d = {str(gens[0]): 0}
411412
tester.assertEqual(self.subs(**d).parent(), self.parent())
412413

414+
# test error checking: partial substitution by elements
415+
# from another ring is not allowed
416+
d = {str(gens[0]): other_gens[0]}
417+
with tester.assertRaises((ValueError, TypeError)):
418+
self.subs(**d)
419+
413420

414421
class MPolynomial_polydict(Polynomial_singular_repr, MPolynomial_element):
415422
r"""

0 commit comments

Comments
 (0)