# HG changeset patch # User Paul Boddie # Date 1693866459 -7200 # Node ID cdd61ff46fb7a9da7b580d69c27ee820a7ff04ef # Parent 8ce9d7c0a3180f8b61a3368baa9db45a044fdeaf Prevent inadvertent mutation of function/method arguments. diff -r 8ce9d7c0a318 -r cdd61ff46fb7 tests/values.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/values.py Tue Sep 05 00:27:39 2023 +0200 @@ -0,0 +1,7 @@ +def test(a): + a = a - 1.0 + return a + +x = 2.0 +print test(x) # 1.0 +print x # 2.0 diff -r 8ce9d7c0a318 -r cdd61ff46fb7 translator.py --- a/translator.py Mon Sep 04 17:55:26 2023 +0200 +++ b/translator.py Tue Sep 05 00:27:39 2023 +0200 @@ -1765,9 +1765,17 @@ # objects, with only floats supporting replaceable values. if expr: - target_ref = TrResolvedNameRef(n.name, ref, is_global=is_global, - location=location) - self.result_target_name = str(target_ref) + # Prevent parameters from becoming result targets. Otherwise, they + # may inadvertently cause the modification of the supplied object. + + parameters = self.importer.function_parameters.get(path) + + if not parameters or n.name not in parameters: + target_ref = TrResolvedNameRef(n.name, ref, is_global=is_global, + location=location) + self.result_target_name = str(target_ref) + else: + self.result_target_name = None # Expression processing is deferred until after any result target has # been set.