[Python-ideas] Re: Extension methods in Python

2021-06-24 Thread Chris Angelico
On Fri, Jun 25, 2021 at 1:54 PM Ricky Teachey wrote: > > Would this feature allow me to declare str objects as not iterable in some > contexts? > > If so, +1. > That depends. If the proposal is to intercept every attribute lookup (parallel to a class's __getattribute__ method), then yes, but if

[Python-ideas] Re: Extension methods in Python

2021-06-24 Thread David Mertz
I've read all the posts in this thread, and am overall at least -0.5 on the idea. I like methods well enough, but mostly it just seems to invite confusion versus the equivalent and existing option of importing functions. I am happy, initially, to stipulate that "some clever technique" is

[Python-ideas] Re: Extension methods in Python

2021-06-24 Thread Ricky Teachey
Would this feature allow me to declare str objects as not iterable in some contexts? If so, +1. On Thu, Jun 24, 2021, 3:22 PM Chris Angelico wrote: > On Fri, Jun 25, 2021 at 3:31 AM Steven D'Aprano > wrote: > > > > Here's a quick and dirty proof of concept I knocked up in about 20 > >

[Python-ideas] Re: Extension methods in Python

2021-06-24 Thread Chris Angelico
On Fri, Jun 25, 2021 at 3:31 AM Steven D'Aprano wrote: > > Here's a quick and dirty proof of concept I knocked up in about 20 > minutes, demonstrating that no deep compiler magic is needed. It's just > a small change to the way `object.__getattribute__` works. > > I've emulated it with my own

[Python-ideas] Re: Extension methods in Python

2021-06-24 Thread Steven D'Aprano
Here's a quick and dirty proof of concept I knocked up in about 20 minutes, demonstrating that no deep compiler magic is needed. It's just a small change to the way `object.__getattribute__` works. I've emulated it with my own base class, since `object` can't be monkey-patched. The proof of

[Python-ideas] Re: Extension methods in Python

2021-06-24 Thread Steven D'Aprano
On Thu, Jun 24, 2021 at 09:19:36AM -0700, Christopher Barker wrote: > Steven, you're making a pretty good case here, but a couple questions: > > 1) The case of newer versions of python adding methods to builtins, like > .bit_length is really compelling. But I do wonder how frequently that comes

[Python-ideas] Re: Extension methods in Python

2021-06-24 Thread Steven D'Aprano
On Thu, Jun 24, 2021 at 12:17:17AM +1000, Chris Angelico wrote: > On Wed, Jun 23, 2021 at 11:25 PM Steven D'Aprano wrote: > > To a first approximation (ignoring shadowing) every dot lookup can be > > replaced with getattr and vice versa: > > > > obj.name <--> getattr(obj, 'name') > > > > A

[Python-ideas] Re: Extension methods in Python

2021-06-24 Thread Simão Afonso
On 2021-06-24 09:19:36, Christopher Barker wrote: > No -- we're not assuming Python users are idiots -- there is an important > difference here: > > from extensions import flatten > flatten(mylist) > > very clearly adds the name `flatten` to the current module namespace. That > itself

[Python-ideas] Re: Extension methods in Python

2021-06-24 Thread Christopher Barker
Steven, you're making a pretty good case here, but a couple questions: 1) The case of newer versions of python adding methods to builtins, like .bit_length is really compelling. But I do wonder how frequently that comes up. It seems to me on this list, that people are very reluctant to add

[Python-ideas] Re: Extension methods in Python

2021-06-24 Thread Rob Cliffe via Python-ideas
On 24/06/2021 12:44, Richard Damon wrote: On 6/24/21 7:09 AM, Simão Afonso wrote: On 2021-06-24 20:59:31, Steven D'Aprano wrote: Seriously, there's a time to realise when arguments against a feature devolve down to utterly spurious claims that Python programmers are idiots who will be

[Python-ideas] Re: Extension methods in Python

2021-06-24 Thread Richard Damon
On 6/24/21 7:09 AM, Simão Afonso wrote: > On 2021-06-24 20:59:31, Steven D'Aprano wrote: >> Seriously, there's a time to realise when arguments against a feature >> devolve down to utterly spurious claims that Python programmers are >> idiots who will be confused by: >> >> from extensions

[Python-ideas] Re: Extension methods in Python

2021-06-24 Thread Simão Afonso
On 2021-06-24 20:59:31, Steven D'Aprano wrote: > Seriously, there's a time to realise when arguments against a feature > devolve down to utterly spurious claims that Python programmers are > idiots who will be confused by: > > from extensions use flatten > mylist.flatten() > > but can

[Python-ideas] Re: Extension methods in Python

2021-06-24 Thread Steven D'Aprano
On Wed, Jun 23, 2021 at 11:22:26AM -0700, Brendan Barnwell wrote: > 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

[Python-ideas] Re: Extension methods in Python

2021-06-24 Thread Chris Angelico
On Thu, Jun 24, 2021 at 7:51 PM Steven D'Aprano wrote: > > I'm not sure if you completely understand the use-case I was describing, > so let me clarify for you with a concrete example. > > Ints have a "bit_length" method, starting from Python 2.7. I needed to > use that method going all the way

[Python-ideas] Re: Extension methods in Python

2021-06-24 Thread Steven D'Aprano
Oops, sorry, I neglected to trim my response to João. Please ignore my previous response, with the untrimmed quoting at the start, and give any replies to this. On Wed, Jun 23, 2021 at 07:23:19PM +0200, João Santos wrote: > Of course that means the the standard library might also introduce

[Python-ideas] Re: Extension methods in Python

2021-06-24 Thread Steven D'Aprano
On Wed, Jun 23, 2021 at 07:23:19PM +0200, João Santos wrote: > > > 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

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

2021-06-24 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