[Python-ideas] Wild idea about mutability

Michael Selik michael.selik at gmail.com
Thu Jun 2 10:11:04 EDT 2016


On Wed, Jun 1, 2016 at 9:35 PM Steven D'Aprano <steve at pearwood.info> wrote:

> On Wed, Jun 01, 2016 at 11:26:07PM +0100, Rob Cliffe wrote:
> > It could be an optional extra
> > argument to mutable object constructors (so you have the option of
> > making them immutable):
> >
> >     L = list(somesequence, mutable=False)
>
> This goes against the "no constant bool arguments" design guideline.
>

That was a recent discussion and Guido suggested it was unlikely anyone
would need an optional boolean flag to be dynamic in the code. It would be
much more likely that the call site would always pick one or the other and
that flag could be constant. If it's a constant, then it'd be better to
have two different well-named constructors, rather than a boolean parameter.

Thus to evaluate this idea, we should ask:
Would any call site need to set that flag dynamically?

If it's simply a tool for introspection, rather than construction, how
often do you find yourself checking for is-mutable?
    immutables = (str, bytes, int, float, complex, bool, tuple, frozenset)
    if isinstance(obj, immutables):
        ...

I don't think I've ever made that check. I've checked for is-basic-type,
but that's different.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160602/ff00a290/attachment.html>


More information about the Python-ideas mailing list