I really like this idea.  Once you've already decided to raise an
exception, does it really cost much to try to raise a more helpful one?
And helpful exception messages make programming a lot less painful, and a
lot more of a joy.

On Tue, Oct 22, 2019 at 2:43 PM Mike Miller <python-id...@mgmiller.net>
wrote:

>
> On 2019-10-18 10:23, Ricky Teachey wrote:
> > but i'm -0 because i am very concerned it will not be obvious to new
> learners,
> > without constantly looking it up, whether adding two mappings together
> would either:
>
> The big trade off I'm gathering from this mega-thread is that the |, |=
> operators are more accurate, but less obvious to newcomers, who will first
> try
> +, += instead.
>
> I've tried them in this order myself several times over the years.
>
> Had an idea, why not choose the more accurate syntax: |, |= after all?
> Then, to
> help newcomers and forgetful pros a custom error message is implemented
> for +,
> +=.  In pseudo C/Python, something like this:
>
>      class dict:
>
>          def __add__(self, other):
>
>              if isinstance(other, dict):
>                  raise TypeError(
>                      'unsupported operand type(s) for +: … '
>                      'Dictionary merging leads to last-value-wins data '
>                      'loss. If acceptable, use the union "|" operator.'
>                  )
>              else:
>                  raise TypeError(std_err_msg)
>
>
> I think it is worth it to lead the newcomer to a moment's reflection on
> why
> dictionary combining/merging is potentially lossy.  Everyone is informed
> with
> the proper mental model, then on their way and left alone afterward.
>
> Thoughts?
> -Mike
> _______________________________________________
> 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/43T52R223GYPHIDP3CHTIS3JTQYUNCVL/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
> --
>
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "python-ideas" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/python-ideas/puGRBmzVl9c/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> python-ideas+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python-ideas/3ac803c4-f703-67bf-c4c9-a37bbe0c61d8%40mgmiller.net
> .
>
_______________________________________________
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/3UGDM5QPUYVABW35MM7DGACWBYFBK2CT/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to