Re: [Python-Dev] Monkeypatching idioms -- elegant or ugly?

2008-01-31 Thread nathan binkert
> Have you tried this? I believe it doesn't even work; types defined in > C++ are supposed to be immutable. Try adding a new method to list or > dict. I noticed that and I was trying to figure out if I could create a new metatype which would add a __dict__ and a method (called add_method or somethi

Re: [Python-Dev] Monkeypatching idioms -- elegant or ugly?

2008-01-31 Thread Guido van Rossum
On Jan 31, 2008 9:49 AM, nathan binkert <[EMAIL PROTECTED]> wrote: > Another thing about monkeypatching is that it seems like the best way > to write an extension class where you want half to be in C/C++ and > half in Python. I'm in the middle of working on such a class and > there are plenty of m

Re: [Python-Dev] Monkeypatching idioms -- elegant or ugly?

2008-01-31 Thread nathan binkert
Another thing about monkeypatching is that it seems like the best way to write an extension class where you want half to be in C/C++ and half in Python. I'm in the middle of working on such a class and there are plenty of members that just don't need to be in C++. Is there a better/preferred idio

Re: [Python-Dev] Monkeypatching idioms -- elegant or ugly?

2008-01-31 Thread Guido van Rossum
On Jan 30, 2008 9:00 PM, Kevin Teague <[EMAIL PROTECTED]> wrote: > +1 on having established Python idioms for these techniques. > > While I don't know if there has ever been a formal definition of > monkey patch, the term monkey patch came from guerilla patch, which > came from two or more dynamic

[Python-Dev] Monkeypatching idioms -- elegant or ugly?

2008-01-30 Thread Kevin Teague
+1 on having established Python idioms for these techniques. While I don't know if there has ever been a formal definition of monkey patch, the term monkey patch came from guerilla patch, which came from two or more dynamic modifications to a class interfering with each other. These modifica

Re: [Python-Dev] Monkeypatching idioms -- elegant or ugly?

2008-01-20 Thread Andrew McNamara
>I think that despite the objection that monkeypatching shoudn't be >made too easy, it's worth at looking into a unification of the API, >features, and implementation. I agree. The other virtue of having it in the standard library is that it's immediately recognisable for what it is. -- Andrew M

Re: [Python-Dev] Monkeypatching idioms -- elegant or ugly?

2008-01-19 Thread Martin v. Löwis
> In Objective-C it's perfectly common to extend existing classes using > 'categories' and I have often found this idiom very useful. What is > described here is basically categories for Python. I've implemented > something like this before and I would be happy to see this added to > the

Re: [Python-Dev] Monkeypatching idioms -- elegant or ugly?

2008-01-19 Thread Nicko van Someren
On 15 Jan 2008, at 15:37, Guido van Rossum wrote: > Second, a "metaclass" to add a number of methods (or other attributes) > to an existing class, using a convenient class notation: ... > class (): >__metaclass__ = monkeypatch_class >def (...): ... >def (...): ... >... In Objective

Re: [Python-Dev] Monkeypatching idioms -- elegant or ugly?

2008-01-15 Thread Martin v. Löwis
> Second, a "metaclass" to add a number of methods (or other attributes) > to an existing class, using a convenient class notation: I think this is similar to my "partial" classes: http://pypi.python.org/pypi/partial Regards, Martin ___ Python-Dev mail

Re: [Python-Dev] Monkeypatching idioms -- elegant or ugly?

2008-01-15 Thread Guido van Rossum
On Jan 15, 2008 2:08 PM, Phillip J. Eby <[EMAIL PROTECTED]> wrote: > At 01:51 PM 1/15/2008 -0800, Guido van Rossum wrote: > >On Jan 15, 2008 1:27 PM, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote: > > > > Second, a "metaclass" to add a number of methods (or other attributes) > > > > to an existing cl

Re: [Python-Dev] Monkeypatching idioms -- elegant or ugly?

2008-01-15 Thread Phillip J. Eby
At 01:51 PM 1/15/2008 -0800, Guido van Rossum wrote: >On Jan 15, 2008 1:27 PM, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote: > > > Second, a "metaclass" to add a number of methods (or other attributes) > > > to an existing class, using a convenient class notation: > > > > I think this is similar to

Re: [Python-Dev] Monkeypatching idioms -- elegant or ugly?

2008-01-15 Thread Guido van Rossum
On Jan 15, 2008 1:27 PM, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote: > > Second, a "metaclass" to add a number of methods (or other attributes) > > to an existing class, using a convenient class notation: > > I think this is similar to my "partial" classes: > > http://pypi.python.org/pypi/partial

[Python-Dev] Monkeypatching idioms -- elegant or ugly?

2008-01-15 Thread Stephen J. Turnbull
Guido van Rossum writes: > I think it's useful to share these recipes, But only to people who have demonstrated that they already know when, why and how to monkeypatch on their own. Lisp's `defadvice' plays a starring role in a number of my nightmares. Most recently, 15 minutes ago. Come to t

Re: [Python-Dev] Monkeypatching idioms -- elegant or ugly?

2008-01-15 Thread Guido van Rossum
On Jan 15, 2008 8:22 AM, Antoine Pitrou <[EMAIL PROTECTED]> wrote: > pypy has something that requires the base class to use a specific metaclass: > https://codespeak.net/viewvc/pypy/dist/pypy/tool/pairtype.py?view=markup That's no good for my particular use case. -- --Guido van Rossum (home page

Re: [Python-Dev] Monkeypatching idioms -- elegant or ugly?

2008-01-15 Thread Antoine Pitrou
Guido van Rossum python.org> writes: > > I ran into the need of monkeypatching a large number of classes (for > what I think are very good reasons and invented two new recipes. > These don't depend on Py3k, and the second one actually works all the > way back to Python 2.2. Neither of these allo

Re: [Python-Dev] Monkeypatching idioms -- elegant or ugly?

2008-01-15 Thread Robert Brewer
Guido van Rossum: > I ran into the need of monkeypatching a large number of classes (for > what I think are very good reasons :-) and invented two new recipes. > These don't depend on Py3k, and the second one actually works all the > way back to Python 2.2. Neither of these allows monkeypatching >

Re: [Python-Dev] Monkeypatching idioms -- elegant or ugly?

2008-01-15 Thread Steve Holden
[EMAIL PROTECTED] wrote: > On 03:37 pm, [EMAIL PROTECTED] wrote: >> I think it's useful to share these recipes, if only to to establish >> whether they have been discovered before, or to decide whether they >> are worthy of a place in the standard library. I didn't find any >> relevant hits on the

Re: [Python-Dev] Monkeypatching idioms -- elegant or ugly?

2008-01-15 Thread glyph
On 03:37 pm, [EMAIL PROTECTED] wrote: >I think it's useful to share these recipes, if only to to establish >whether they have been discovered before, or to decide whether they >are worthy of a place in the standard library. I didn't find any >relevant hits on the ASPN Python cookbook. >from impor

[Python-Dev] Monkeypatching idioms -- elegant or ugly?

2008-01-15 Thread Guido van Rossum
I ran into the need of monkeypatching a large number of classes (for what I think are very good reasons :-) and invented two new recipes. These don't depend on Py3k, and the second one actually works all the way back to Python 2.2. Neither of these allows monkeypatching built-in types like list. If