[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 []. Howe

[Python-ideas] Provide an asynchronus equivalent to itertools.chain, and possibly more of itertools

2022-05-31 Thread rammers2
I recently started to dive into asynchronous programming in Python. My program iterates over text from posts on a website and analyses it. I wanted to add the ability to asynchronously apply the same analysis to posts from multiple websites. It seemed likely to me that this would be something pe

[Python-ideas] Opt-in “iter def” and/or “gen def” syntax for generator functions

2022-05-31 Thread Aaron L via Python-ideas
After getting used to writing async functions, I’ve been wanting use a similar syntax to declare generator functions. Something along the lines of `iter def my_iterator() -> T` and/or `gen def my_generator() -> (T, U, V)` Obviously, for backwards compatibility, this would need to be optional

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

2022-05-31 Thread Eric Fahlgren
On Tue, May 31, 2022 at 5:54 AM fjwillemsen--- via Python-ideas < [email protected]> wrote: > 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 th

[Python-ideas] Re: Opt-in “iter def” and/or “gen def” syntax for generator functions

2022-05-31 Thread Chris Angelico
On Tue, 31 May 2022 at 23:00, Aaron L via Python-ideas wrote: > > After getting used to writing async functions, I’ve been wanting use a > similar syntax to declare generator functions. Something along the lines of > > `iter def my_iterator() -> T` > > and/or > > `gen def my_generator() -> (T, U

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

2022-05-31 Thread Jonathan Fine
Here is another problem in this general area. Multiplying an array by a float already raises a type error. >>> []*0.0 Traceback (most recent call last): TypeError: can't multiply sequence by non-int of type 'float' This problem can arrse 'by accident'. For example, consider >>> x =

[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, develo

[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

[Python-ideas] Re: Opt-in “iter def” and/or “gen def” syntax for generator functions

2022-05-31 Thread Aaron L via Python-ideas
Thanks for your reply. > What's the advantage? I brought this up thinking about explicitness and readability. Say you want to figure out what this function is doing: def foo() -> t.Iterator[T]: [... 300 lines of code] ``` Is this a generator function? I'd argue that whether it's a ge

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

2022-05-31 Thread Christopher Barker
Two contradictory opinions from me :-) 1) multiplying a list or a bumpy array be an integer are very different operations — and in most cases, the result will be a different size (and type), which is the case in this example. So it’s rarely a hard to find bug. So that’s not a very compelling argum

[Python-ideas] Re: Opt-in “iter def” and/or “gen def” syntax for generator functions

2022-05-31 Thread Chris Angelico
On Wed, 1 Jun 2022 at 03:34, Aaron L via Python-ideas wrote: > > Thanks for your reply. > > > What's the advantage? > > I brought this up thinking about explicitness and readability. Say you want > to figure out what this function is doing: > > > def foo() -> t.Iterator[T]: > [... 300 li

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

2022-05-31 Thread Chris Angelico
On Wed, 1 Jun 2022 at 03:41, Christopher Barker wrote: > In fact, I don’t think there’s been a breaking change since the Py3 > transition. > > I think PEP 563 was going to be the first — and that’s been delayed. Depends on your definition of "breaking". For instance, this code is legal in Python

[Python-ideas] Re: Opt-in “iter def” and/or “gen def” syntax for generator functions

2022-05-31 Thread Aaron L via Python-ideas
I don't really disagree with most of what you wrote! And agree that decorators, specifically, are a pretty good solution within the scope of an individual package. But I would quibble with this: >How fundamental is it that THIS function is a generator, rather than simply >that > it returns an

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

2022-05-31 Thread Steven D'Aprano
On Mon, May 30, 2022 at 02:31:35PM -, fjwillemsen--- via Python-ideas wrote: > 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]. It certainly does not do that. >>> [1, 2, 3]*2 [1, 2, 3, 1, 2, 3] Also, that's a lis