On Thu, Apr 28, 2022 at 4:15 PM Ethan Furman <et...@stoneleaf.us> wrote:

>  > NOTE: another key question for this proposal is how you would handle
> mutable defaults -- anything
>  > special, or "don't do that"?
>
> Why should they be handled at all?  If the programmer writes
>
>      def __init__(a, @b, @c=[]):
>          pass
>
> then all instances that didn't have `c` given will share the same list --
> just like if the code was:
>
>      def __init__(a, b, c=[]):
>          self.b = b
>          self.c = c
>

so the answer is "don't do that" (unless, in the rare case, that's what you
actually want).

The purpose of the syntax is to automatically save arguments to same-named
> attributes, not to perform any other magic.


> If the programmer writes

     def __init__(a, @b, @c=[]):
         pass

sure but that's the coon case -- more common would be:

    def __init__(a, @b, c=None):
        handle_a
        if c is None:
            c = []

or some such.

so  without "any other magic", then we have a less useful proposal. One
thing you can say about dataclasses is that they provide a way to handle
all parameters, mutable and immutable.

Anyway, I just thought it should be clearly said.

-CHB

-- 
Christopher Barker, PhD (Chris)

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/HYRQPWXMPJ727FQWEJ4GY2SMUEABKEGW/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to