Thank you, that is a good point! I would expect a similar error message for multiplication with negative integers. A real-world example could be the scenario where I encountered this: arrays were consistently assumed to be NumPy arrays, but in some cases cached versions of these arrays would be loaded from a JSON file without casting them to a NumPy array. Because the function signatures all state NumPy arrays, I applied an array * -1 operation before interpolation and other operations, in the expectation that this would yield the inverse of the elements instead of an empty list. It took me a while to find out that the problem was not in the interpolation or other operations following it, but in the array type. Of course, such bugs do not occur solely due to the lack of a raised errors on negative multiplication: in this case, a combination of a faulty assumption on the programmers' part and Python's lack of strict typing. However, raising an error on negative multiplication would immediately make it clear what is wrong, instead of hiding it. _______________________________________________ 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/U4YXU3KIMCCZ4XFGSZVVMCBF6MJDNNEW/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: Python array multiplication for negative values should throw an error
fjwillemsen--- via Python-ideas Tue, 31 May 2022 08:41:05 -0700
- [Python-ideas] Python array multiplication... fjwillemsen--- via Python-ideas
- [Python-ideas] Re: Python array multi... Eric Fahlgren
- [Python-ideas] Re: Python array m... Jonathan Fine
- [Python-ideas] Re: Python arr... fjwillemsen--- via Python-ideas
- [Python-ideas] Re: Python... Stephen J. Turnbull
- [Python-ideas] Re: Python array m... fjwillemsen--- via Python-ideas
- [Python-ideas] Re: Python arr... Christopher Barker
- [Python-ideas] Re: Python... Chris Angelico
- [Python-ideas] Re: Python array multi... Steven D'Aprano