Re: [Python-ideas] Redefining method

2018-08-20 Thread Jamesie Pic
Sorry if my message offended anyone (noted that the "Toxic Forum" post came not long after mine). What I meant is that I cannot defend such an idea before extensively using it. I just don't know how to do it this way. Have a great day ___ Python-ideas

Re: [Python-ideas] Redefining method

2018-07-31 Thread Jamesie Pic
I like type() a lot, and the attributes dict it takes as argument works with lambda. My use case is just a python module for a framework provides a default instance for some model, and I thought it would be cool to just change a method without going through I'm really bad at defending ideas,

Re: [Python-ideas] Redefining method

2018-07-30 Thread Stephan Houben
Here is an example of how it could be done. https://gist.github.com/stephanh42/97b47506e5e416f97f5790c070be7878 Stephan Op di 31 jul. 2018 01:29 schreef Steven D'Aprano : > On Tue, Jul 31, 2018 at 10:10:32AM +1200, Greg Ewing wrote: > > Jamesie Pic wrote: > > >def o.bar(self): ... > > > > You

Re: [Python-ideas] Redefining method

2018-07-30 Thread Steven D'Aprano
On Tue, Jul 31, 2018 at 10:10:32AM +1200, Greg Ewing wrote: > Jamesie Pic wrote: > >def o.bar(self): ... > > You could get almost the same effect with > >from functools import partial > >def bar(self, other_args): > ... > >o.bar = partial(bar, o) Why are you using

Re: [Python-ideas] Redefining method

2018-07-30 Thread Greg Ewing
Jamesie Pic wrote: def o.bar(self): ... You could get almost the same effect with from functools import partial def bar(self, other_args): ... o.bar = partial(bar, o) But IMO this is nowhere near being a common enough thing to do to justify having special syntax for it. --

Re: [Python-ideas] Redefining method

2018-07-30 Thread Kyle Lahnakoski
I think C# calls methods that are added to a class "extension methods". You can make a decorator that will do that for you: > def extend(cls): >     """ >     DECORATOR TO ADD METHODS TO CLASSES >     :param cls: THE CLASS TO ADD THE METHOD TO >     :return: >     """ >     def extender(func): >

Re: [Python-ideas] Redefining method

2018-07-30 Thread Chris Barker via Python-ideas
On Mon, Jul 30, 2018 at 9:10 AM, Nick Coghlan wrote: If you need to replace them for some reason, it will preferably be > within a temporary bounded scope, using a tool like > unittest.mock.patch, rather than as a permanent change that affects > every other use of the class within the process.

Re: [Python-ideas] Redefining method

2018-07-30 Thread Jonathan Fine
Hi Jamesie Thank you for your question. You asked why not > c = MyClass > o = c() > > def c.foo(cls): ... > def o.bar(self): ... I've the same same query, but never had the courage to ask. So that you for asking. And also giving me a chance to share my thoughts. In Ruby, I believe, you can