[Python-ideas] Re: Flatten function (was: Deprecate sum of lists)

2021-06-20 Thread Oscar Benjamin
On Sun, 20 Jun 2021 at 23:29, Greg Ewing wrote: > > On 21/06/21 6:04 am, Sebastian Berg wrote: > > * `flatten()` (alwasy copy) > > * `ravel()` (copies if needed, and additionally ensures contiguity) > > * `reshape(-1)` (copies if needed) > > > > They are all subtly different, unfortunately. > >

[Python-ideas] Re: Extension methods in Python

2021-06-20 Thread William Pickard
Your assumption about requiring some form of registration system for Python to implement extensions is correct as Roslyn (The C# compiler) resolves them at compile time (as long as the namespace is imported/the class is in the "global" namespace) When I said static function, it's basically me

[Python-ideas] Re: Extension methods in Python

2021-06-20 Thread Steven D'Aprano
Hi William, Thanks for the description of C# extension methods, but I think that like Britons and Americans, we're in danger of being divided by a common language. (To paraphrase Churchill.) On Sun, Jun 20, 2021 at 10:56:37PM -, William Pickard wrote: > While IDK about Kotlin's extension

[Python-ideas] Re: Extension methods in Python

2021-06-20 Thread Soni L.
On 2021-06-20 7:48 p.m., Steven D'Aprano wrote: > The technique you are calling "extension methods" is known as > "monkey-patching" in Python and Ruby. > > With respect to a fine language, Kotlin, it doesn't have the user-base > of either Python or Ruby. Python does not allow monkey-patching

[Python-ideas] Re: Extension methods in Python

2021-06-20 Thread William Pickard
While IDK about Kotlin's extension methods, I do know that C# (A highly popular programming language) also has extension methods so I'll talk about those. In C#, extension methods are plain static functions defined in a plain static class, the only key difference between normal static methods

[Python-ideas] Re: Extension methods in Python

2021-06-20 Thread Steven D'Aprano
The technique you are calling "extension methods" is known as "monkey-patching" in Python and Ruby. With respect to a fine language, Kotlin, it doesn't have the user-base of either Python or Ruby. Python does not allow monkey-patching builtin classes, but Ruby does:

[Python-ideas] Re: Flatten function (was: Deprecate sum of lists)

2021-06-20 Thread Greg Ewing
On 21/06/21 6:04 am, Sebastian Berg wrote: * `flatten()` (alwasy copy) * `ravel()` (copies if needed, and additionally ensures contiguity) * `reshape(-1)` (copies if needed) They are all subtly different, unfortunately. There's also a .flat attribute, that returns a 1-d iterator! -- Greg

[Python-ideas] Fill in missing contextvars/asyncio task support

2021-06-20 Thread Mark Gordon
With normal synchronous code you can use `contextvars.Context.run()` to change what context code is executing within. However, there is no analagous concept for asyncio code. I'm proposing something similar, for example: coro = foo() my_context = convextvars.Context() await

[Python-ideas] Re: Flatten function (was: Deprecate sum of lists)

2021-06-20 Thread David Mertz
On Sun, Jun 20, 2021, 2:07 PM Sebastian Berg > NumPy has: > > * `flatten()` (always copy) > * `ravel()` (copies if needed, and additionally ensures contiguity) > * `reshape(-1)` (copies if needed) > > They are all subtly different, unfortunately. > Oops! Sebastian is right, and I made an error.

[Python-ideas] Re: Flatten function (was: Deprecate sum of lists)

2021-06-20 Thread Sebastian Berg
On Sun, 2021-06-20 at 13:48 -0400, David Mertz wrote: > On Sun, Jun 20, 2021 at 1:07 PM Christopher Barker < > python...@gmail.com> > wrote: > > > Flatten is used in numpy: > > Where it is a method, and goes all the way to one dimension. > > > > I think it's worth keeping in mind the

[Python-ideas] Flatten function (was: Deprecate sum of lists)

2021-06-20 Thread David Mertz
On Sun, Jun 20, 2021 at 1:07 PM Christopher Barker wrote: > Flatten is used in numpy: > Where it is a method, and goes all the way to one dimension. > I think it's worth keeping in mind the differences though. In NumPy, arr.flatten() doesn't even TOUCH the array itself. It is solely a

[Python-ideas] Re: Deprecate sum of lists

2021-06-20 Thread Christopher Barker
Flatten is used in numpy: https://numpy.org/doc/stable/reference/generated/numpy.ndarray.flatten.html?highlight=flatten#numpy.ndarray.flatten Where it is a method, and goes all the way to one dimension. A builtin flatten can’t be the same, but it would be nice if it weren’t too different. e.g.

[Python-ideas] Re: Extension methods in Python

2021-06-20 Thread 2QdxY4RzWzUUiLuE
On 2021-06-20 at 12:18:24 -, Johan Vergeer wrote: > After working with Kotlin for a while I really started to like the > idea of extension methods. I delivers a great way to extend the > language without having to add features to the language itself. I disagree with the premise that such a

[Python-ideas] Re: Extension methods in Python

2021-06-20 Thread Rob Cliffe via Python-ideas
What objection do you have to creating a subclass? Adding methods to e.g. list could give you problems if you import 2 modules that each modify list and the modifications are incompatible.  It could conceivably add bugs to code that uses list in a standard way. Best wishes Rob Cliffe On

[Python-ideas] Extension methods in Python

2021-06-20 Thread Johan Vergeer
After working with Kotlin for a while I really started to like the idea of extension methods. I delivers a great way to extend the language without having to add features to the language itself. As a practical example I would like to take a first item from a list my_list = [] first =

[Python-ideas] Re: Allow modifying message of TypeError from NotImplemented

2021-06-20 Thread Serhiy Storchaka
19.06.21 06:30, wyz2...@163.com пише: > Python raises TypeError when NotImplemented is returned from __add__, > __invert__ etc. and __radd__ etc. aren't available. > However, this disallows the customization of error messages. For example, in > Python 3.8, __float__ etc. were removed from