-
Notifications
You must be signed in to change notification settings - Fork 81
lp.Reduction.inames_set must return frozenset #995
Copy link
Copy link
Closed
Description
Returning mutable objects from memoized routines is dangerous.
(py314_env) kaushikggg@line:~/temp$ cat tmp.py
import loopy as lp
def _get_iname_set(redn: lp.Reduction) -> frozenset[str]:
iname_frozenset = frozenset(redn.inames_set)
redn.inames_set.add("i am introducing a bug.")
return iname_frozenset
def _get_sorted_inames(redn: lp.Reduction) -> tuple[str, ...]:
return tuple(sorted(redn.inames_set))
if __name__ == "__main__":
from loopy.symbolic import parse
expr = parse("sum(i, i**2)")
print(_get_iname_set(expr))
print(_get_sorted_inames(expr))
(py314_env) kaushikggg@line:~/temp$ python tmp.py
frozenset({'i'})
('i', 'i am introducing a bug.')Reactions are currently unavailable