sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.41k stars 474 forks source link

SymbolicRing._force_pyobject: Make immutable copies of mutable objects #32450

Open mkoeppe opened 3 years ago

mkoeppe commented 3 years ago

SymbolicRing can wrap pretty arbitrary Python objects as SR elements. Lots of things can obviously go wrong with that, but allowing expressions to be effectively mutable is going too far.

sage: m = matrix(QQ, 2, 2)
sage: M = SR(m)
sage: type(M)
<class 'sage.symbolic.expression.Expression'>
sage: m[0,1] = 8
sage: M
[0 8]
[0 0]

We should make an immutable copy before wrapping.

Depends on #32391

CC: @tscrim @mjungmath @nbruin @kwankyu @orlitzky

Component: symbolics

Issue created by migration from https://trac.sagemath.org/ticket/32450

mkoeppe commented 3 years ago

Dependencies: #32391