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

2021-06-23 Thread Mark Gordon
I've read the PEP and understand what's implemented. However there is pretty limited discussion about what the design constraints were and what intended/recommended usage would look like. I'll answer my own question: 1. If all we wanted was a version of TLS that worked in an analogous way exten

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

2021-06-23 Thread Paul Bryan
On Wed, 2021-06-23 at 21:18 -0700, yselivanov...@gmail.com wrote: > I'm +1 to add a 'context' keyword-argument to > 'asyncio.create_task()'. It will still be copied. I believe I've > explained *why* the copy is still necessary in this thread. +1. Paul ___

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

2021-06-23 Thread yselivanov . ml
On Wed, Jun 23 2021 at 05:16:00 PM -, Mark Gordon wrote: That's a feature :) Perhaps we should add an example to the docs. What do you view as the point of the copy semantics, then? Are you asking why the context is using immutable data-structures internally, in the first place? Ple

[Python-ideas] Re: Extension methods in Python

2021-06-23 Thread Brendan Barnwell
On 2021-06-23 03:02, Steven D'Aprano wrote: Attribute lookups are just another form of name lookup. Name lookups depend on the current execution scope, not the caller's scope. With extension methods, so do attribute lookups. But that's the thing, they aren't. You gave a bunch of examples of

[Python-ideas] Re: Extension methods in Python

2021-06-23 Thread João Santos
On Wed, Jun 23 2021 at 20:48:39 +1000, Steven D'Aprano wrote: I've just thought of a great use-case for extension methods. Hands up who has to write code that runs under multiple versions of Python? *raises my hand* I'm sure I'm not the only one. You probably have written compatibility func

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

2021-06-23 Thread Mark Gordon
> That's a feature :) Perhaps we should add an example to the docs. What do you view as the point of the copy semantics, then? > There's not much wrong about this approach for simple coroutines. But > if a coroutine runs its own tasks or code that forks the context > inside, you won't see those

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

2021-06-23 Thread yselivanov . ml
On Tue, Jun 22 2021 at 04:40:45 AM -, Mark Gordon wrote: Yury Selivanov wrote: On Mon, Jun 21, 2021 at 7:20 PM Mark Gordon msg...@gmail.com wrote: > Yeah, it would indeed inherit the copy. We could, theoretically, make > asyncio.Task accept context objects a

[Python-ideas] Re: Extension methods in Python

2021-06-23 Thread Chris Angelico
On Wed, Jun 23, 2021 at 11:25 PM Steven D'Aprano wrote: > > On Wed, Jun 23, 2021 at 03:47:05PM +1000, Chris Angelico wrote: > > > Okay. Lemme give it to you *even more clearly* since the previous > > example didn't satisfy. > > > > # file1.py > > > > @extend(list) > > def in_order(self): > > r

[Python-ideas] Re: Extension methods in Python

2021-06-23 Thread Soni L.
On 2021-06-23 10:21 a.m., Steven D'Aprano wrote: > > What about other functions implemented in C? If I write a C module > > that calls PyObject_GetAttr, does it behave as if dot notation were > > used in the module that called me, or does it use my module's > > extension methods? > > That depend

[Python-ideas] Re: Extension methods in Python

2021-06-23 Thread Steven D'Aprano
On Wed, Jun 23, 2021 at 03:47:05PM +1000, Chris Angelico wrote: > Okay. Lemme give it to you *even more clearly* since the previous > example didn't satisfy. > > # file1.py > > @extend(list) > def in_order(self): > return sorted(self) > > def frob(stuff): > return stuff.in_order() > >

[Python-ideas] Re: Extension methods in Python

2021-06-23 Thread Soni L.
On 2021-06-23 5:21 a.m., Steven D'Aprano wrote: > On Tue, Jun 22, 2021 at 08:44:56AM -0300, Soni L. wrote: > > > Oh this is a long one. > > > > Hypothetically, let's say you have a proxy object: > > > > class Foo: > >   def __getattribute__(self, thing): > >     return getattr(super().__getattr

[Python-ideas] Re: Extension methods in Python

2021-06-23 Thread Steven D'Aprano
I've just thought of a great use-case for extension methods. Hands up who has to write code that runs under multiple versions of Python? *raises my hand* I'm sure I'm not the only one. You probably have written compatibility functions like this: def bit_length(num): try:

[Python-ideas] Re: Extension methods in Python

2021-06-23 Thread Steven D'Aprano
On Tue, Jun 22, 2021 at 11:43:09AM -0700, Brendan Barnwell wrote: > ### file1.py > @extend(list) > def len2(self): > return len(self)**2 > > ### file2.py > # or whatever I do to say "I want to use extensions to list defined in > file1" > from file1 extend list > > def coolness(some_list):

[Python-ideas] Re: Extension methods in Python

2021-06-23 Thread Chris Angelico
On Wed, Jun 23, 2021 at 6:49 PM Brendan Barnwell wrote: > There aren't many things in Python that work this way. Future imports > are the main one, but those are rare (and rightly so). The import > machinery itself provides some possibility for this (as used by stuff > like macropy) but

[Python-ideas] Re: Extension methods in Python

2021-06-23 Thread Chris Angelico
On Wed, Jun 23, 2021 at 6:25 PM Steven D'Aprano wrote: > Soni, and Chris, you seem to be responding as if extension methods are > clearly, obviously and self-evidently a stupid idea. Let me remind you > that at least ten languages (C#, Java, Typescript, Oxygene, Ruby, > Smalltalk, Kotlin, Dart, VB

[Python-ideas] Re: Extension methods in Python

2021-06-23 Thread Brendan Barnwell
On 2021-06-22 15:35, Soni L. wrote: Imagine if Python didn't have an + operator, but instead an + *infix function*. Thus, every module would automatically include the global def infix +(left, right): ... And indeed, you could say we already have this. Except currently you can't define your

[Python-ideas] Re: Extension methods in Python

2021-06-23 Thread Steven D'Aprano
On Tue, Jun 22, 2021 at 08:44:56AM -0300, Soni L. wrote: > Oh this is a long one. > > Hypothetically, let's say you have a proxy object: > > class Foo: >   def __getattribute__(self, thing): >     return getattr(super().__getattribute__(self, "proxied"), thing) > > Should this really include ex