[Python-ideas] Proposal to change List Sequence Repetition (*) so it is not useless for Mutable Objects

Joseph Martinot-Lagarde contrebasse at gmail.com
Tue May 31 09:36:31 EDT 2016

> I can only agree here. Even today, despite knowing the fact, it's 
> causing some headaches in some cases.

How about raising an exception if mutable objects are in the list ? It's a
pretty big backward incompatible change, but:

- it "works" in the general case
- it avoids hidden bugs
- it avoids a transition period between new and old behavior
- it is possible to propose using a list comprehension instead in the
exception message

- backward incompatible (but changing the behavior of * is backward
incompatible anyway)
- maybe there are useful use cases of duplicating the reference ?

Note that the same arguments could be taken for mutable default arguments,
but an actual use case is to create a cache variable.


More information about the Python-ideas mailing list