[Python-ideas] Re: Python array multiplication for negative values should throw an error

2022-05-31 Thread fjwillemsen--- via Python-ideas
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

2022-05-31 Thread fjwillemsen--- via Python-ideas
Thanks for your response. While legacy production code is always an issue with 
potentially breaking changes, this line of thought would mean that future 
versions of Python could never introduce breaking changes. This should not be 
the case and is not the case now: for new Python versions, developers are 
expected to test and check for breaking changes, not just update production 
environments to a new version and hope for the best. The fact that this would 
throw an error instead of the expected empty list should then quickly lead to 
the right solution, whereas the other way around, when you expect an error but 
get an empty list, is hard to debug. That is a tradeoff with a clear winner in 
my opinion.
___
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/IZORCHR4TZLKNSTPM3SKHIVT2K34F5H3/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Python array multiplication for negative values should throw an error

2022-05-31 Thread fjwillemsen--- via Python-ideas
Hopefully this is not a duplicate of an existing thread or in the wrong 
section, first time posting here. 
In Python, array multiplication is quite useful to repeat an existing array, 
e.g. [1,2,3] * 2 becomes [1,2,3,4,5,6]. 
Multiplication by 0 yields an empty array: [1,2,3] * 0 becomes []. 
However, operations such as [numpy array] * -1 are very common to get the 
inverse of an array of numbers. 
The confusion here stems from the lack of type checking: while the programmer 
should check whether the array is a NumPy array or a Python array, this is not 
always done, giving rise to difficult to trace cases where [1,2,3] * -1 yields 
[] instead of [-1,-2,-3]. 
I can not think of good reasons why Python array multiplication should not 
throw an error for negative multipliers, because it is meaningless to have 
array multiplication by negative value in the way it is intended in Python. 
Instead I would propose that array multiplication by negative value throws an 
error. 
I would like to hear your opinions on this matter.
___
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/47DZFIB46JQ55R7QFVVDDR4E2VLN2W3X/
Code of Conduct: http://python.org/psf/codeofconduct/