Re: [Python-Dev] Deprecating "instance method" class

2019-04-08 Thread Robert White
Just PyInstanceMethod_New, and by "adding methods to objects" this is adding C functions to types defined in C. Only appears to be called at module import / creation time. On Mon, Apr 8, 2019 at 10:24 AM Jeroen Demeyer wrote: > On 2019-04-08 17:08, Robert White wrote: > > So we're making pretty

Re: [Python-Dev] Deprecating "instance method" class

2019-04-08 Thread Jeroen Demeyer
On 2019-04-08 17:08, Robert White wrote: So we're making pretty heavy use of PyInstanceMethod_New in our python binding library that we've written for a bunch of in house tools. If this isn't the best / correct way to go about adding methods to objects, what should we be using instead? First of

Re: [Python-Dev] Deprecating "instance method" class

2019-04-08 Thread Robert White
So we're making pretty heavy use of PyInstanceMethod_New in our python binding library that we've written for a bunch of in house tools. If this isn't the best / correct way to go about adding methods to objects, what should we be using instead? On Sun, Apr 7, 2019 at 2:17 AM Jeroen Demeyer wrot

Re: [Python-Dev] Deprecating "instance method" class

2019-04-07 Thread Jeroen Demeyer
On 2019-04-07 09:48, Serhiy Storchaka wrote: total_ordering monkeypatches the decorated class. I'm planning to implement in C methods that implement __gt__ in terms of __lt__ etc. Yes, I understood that. I'm just saying: if you want to make it fast, that's not the best solution. The fastest wo

Re: [Python-Dev] Deprecating "instance method" class

2019-04-06 Thread Serhiy Storchaka
05.04.19 20:56, Jeroen Demeyer пише: On 2019-04-05 19:53, Serhiy Storchaka wrote: At Python level we can monkeypatch __gt__, but not tp_richcompare. Sure, but you're planning to use C anyway so that's not really an argument. total_ordering monkeypatches the decorated class. I'm planning to

Re: [Python-Dev] Deprecating "instance method" class

2019-04-05 Thread Brett Cannon
On Fri, Apr 5, 2019 at 1:11 PM Jeroen Demeyer wrote: > On 2019-04-05 21:58, Brett Cannon wrote: > > Then we can consider improving the documentation if there are > > performance implications. > > Sure, we could write in the docs something like "Don't use this, this is > not what you want. It's sl

Re: [Python-Dev] Deprecating "instance method" class

2019-04-05 Thread Jeroen Demeyer
On 2019-04-05 21:58, Brett Cannon wrote: Then we can consider improving the documentation if there are performance implications. Sure, we could write in the docs something like "Don't use this, this is not what you want. It's slow and there are better alternatives like method descriptors". Sh

Re: [Python-Dev] Deprecating "instance method" class

2019-04-05 Thread Brett Cannon
On Fri, Apr 5, 2019 at 11:30 AM Jeroen Demeyer wrote: > On 2019-04-05 17:46, Guido van Rossum wrote: > > This API is doing no harm, it's not a maintenance > > burden > > What if the following happens? > > 1. For some reason (possibly because of this thread), people discover > instancemethod and s

Re: [Python-Dev] Deprecating "instance method" class

2019-04-05 Thread Jeroen Demeyer
On 2019-04-05 17:46, Guido van Rossum wrote: This API is doing no harm, it's not a maintenance burden What if the following happens? 1. For some reason (possibly because of this thread), people discover instancemethod and start using it. 2. People realize that it's slow. 3. It needs to be

Re: [Python-Dev] Deprecating "instance method" class

2019-04-05 Thread Jeroen Demeyer
On 2019-04-05 19:53, Serhiy Storchaka wrote: At Python level we can monkeypatch __gt__, but not tp_richcompare. Sure, but you're planning to use C anyway so that's not really an argument. ___ Python-Dev mailing list Python-Dev@python.org https://mail.

Re: [Python-Dev] Deprecating "instance method" class

2019-04-05 Thread Christian Heimes
On 05/04/2019 17.46, Guido van Rossum wrote: > Let's stop here. This API is doing no harm, it's not a maintenance > burden, clearly *some* folks have a use for it. Let's just keep it, > okay? There are bigger fish to fry. Sounds good to me. My code is 12 years ago and I can't remember any complain

Re: [Python-Dev] Deprecating "instance method" class

2019-04-05 Thread Serhiy Storchaka
05.04.19 15:33, Jeroen Demeyer пише: On 2019-04-05 15:13, Serhiy Storchaka wrote: It is easy to implement a function in C. Why does it need to be a PyCFunction? You could put an actual method descriptor in the class. In other words, use PyDescr_NewMethod() instead of PyCFunction_New() + PyIn

Re: [Python-Dev] Deprecating "instance method" class

2019-04-05 Thread Guido van Rossum
Let's stop here. This API is doing no harm, it's not a maintenance burden, clearly *some* folks have a use for it. Let's just keep it, okay? There are bigger fish to fry. On Fri, Apr 5, 2019 at 5:36 AM Jeroen Demeyer wrote: > On 2019-04-05 15:13, Serhiy Storchaka wrote: > > It is easy to impleme

Re: [Python-Dev] Deprecating "instance method" class

2019-04-05 Thread Jeroen Demeyer
On 2019-04-05 15:13, Serhiy Storchaka wrote: It is easy to implement a function in C. Why does it need to be a PyCFunction? You could put an actual method descriptor in the class. In other words, use PyDescr_NewMethod() instead of PyCFunction_New() + PyInstanceMethod_New(). It's probably goin

Re: [Python-Dev] Deprecating "instance method" class

2019-04-05 Thread Serhiy Storchaka
05.04.19 14:27, Jeroen Demeyer пише: On 2019-04-05 14:10, Serhiy Storchaka wrote: it can be used to implement accelerated versions of separate methods instead of the whole class. Could you elaborate? I'm curious what you mean. It is easy to implement a function in C. But there is a differenc

Re: [Python-Dev] Deprecating "instance method" class

2019-04-05 Thread Jeroen Demeyer
On 2019-04-05 14:10, Serhiy Storchaka wrote: it can be used to implement accelerated versions of separate methods instead of the whole class. Could you elaborate? I'm curious what you mean. I'm going to use it to further optimize total_ordering. There are so many ways in which total_orderin

Re: [Python-Dev] Deprecating "instance method" class

2019-04-05 Thread Serhiy Storchaka
05.04.19 09:07, Jeroen Demeyer пише: On 2019-04-05 00:57, Greg Ewing wrote: If it's designed for use by things outside of CPython, how can you be sure nothing is using it? Of course I'm not sure. However: 1. So far, nobody in this thread knows of any code using it. 2. So far, nobody in this

Re: [Python-Dev] Deprecating "instance method" class

2019-04-04 Thread Jeroen Demeyer
On 2019-04-05 00:57, Greg Ewing wrote: If it's designed for use by things outside of CPython, how can you be sure nothing is using it? Of course I'm not sure. However: 1. So far, nobody in this thread knows of any code using it. 2. So far, nobody in this thread knows any use case for it. And

Re: [Python-Dev] Deprecating "instance method" class

2019-04-04 Thread Greg Ewing
Christian Heimes wrote: I couldn't find any current code that uses PyInstanceMethod_New. Let's deprecate the feature and schedule it for removal in 3.10. If it's designed for use by things outside of CPython, how can you be sure nothing is using it? -- Greg

Re: [Python-Dev] Deprecating "instance method" class

2019-04-04 Thread Jeroen Demeyer
On 2019-04-04 14:09, Christian Heimes wrote: I couldn't find any current code that uses PyInstanceMethod_New. Let's deprecate the feature and schedule it for removal in 3.10. Done at https://github.com/python/cpython/pull/12685 ___ Python-Dev mailing

Re: [Python-Dev] Deprecating "instance method" class

2019-04-04 Thread Christian Heimes
On 04/04/2019 13.51, Jeroen Demeyer wrote: > During my investigations related to low-level function/method classes, I > came across the "instance method" class. There is a C API for it: > https://docs.python.org/3.7/c-api/method.html > However, it's not used/exposed anywhere in CPython, except as >

[Python-Dev] Deprecating "instance method" class

2019-04-04 Thread Jeroen Demeyer
During my investigations related to low-level function/method classes, I came across the "instance method" class. There is a C API for it: https://docs.python.org/3.7/c-api/method.html However, it's not used/exposed anywhere in CPython, except as _testcapi.instancemethod (for testing its functio