Re: [Zope] Modifying __bases__
--On Freitag, 20. Mai 2005 12:32 Uhr -0400 Dan Pozmanter [EMAIL PROTECTED] wrote: Hey, I noticed that the version of python that ships with zope is restricted, such that when you create an instance of a class, you are no longer able to modify __bases__ for that class object. This is not the case with standard python. Is this intentional? If so, what is the reasoning behind this? You mean the Windows binaries? This should be a standard Python version. However by do you want to modify __bases__? This sounds like a very evil hack to me. What's your usecase? -aj pgp5H2vY29Msi.pgp Description: PGP signature ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
RE: [Zope] Modifying __bases__
Well, when I run it, I am able to do the following: class A: pass class B(A): pass b = B() B.__bases__ = () print B.__bases__ Not so on the version that comes with zope. (B.__bases__ will remain unchanged.) What I aim to do is have the User Object inherit from a custom class (AlienUser). -Original Message- From: Andreas Jung [mailto:[EMAIL PROTECTED] Sent: Friday, May 20, 2005 12:46 PM To: Dan Pozmanter; zope@zope.org Subject: Re: [Zope] Modifying __bases__ --On Freitag, 20. Mai 2005 12:32 Uhr -0400 Dan Pozmanter [EMAIL PROTECTED] wrote: Hey, I noticed that the version of python that ships with zope is restricted, such that when you create an instance of a class, you are no longer able to modify __bases__ for that class object. This is not the case with standard python. Is this intentional? If so, what is the reasoning behind this? You mean the Windows binaries? This should be a standard Python version. However by do you want to modify __bases__? This sounds like a very evil hack to me. What's your usecase? -aj ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
RE: [Zope] Modifying __bases__
Am Freitag, den 20.05.2005, 13:48 -0400 schrieb Dan Pozmanter: Well, when I run it, I am able to do the following: class A: pass class B(A): pass b = B() B.__bases__ = () print B.__bases__ Not so on the version that comes with zope. (B.__bases__ will remain unchanged.) What I aim to do is have the User Object inherit from a custom class (AlienUser). Well, you can just inherit with a class from zopes extension classes. You cannot modify the class bases like this with extension classes. You can work around that like I did with the history (monkey) patch: http://www.zope.org/Members/tino/PatchHistory/view Otherwise it sounds evil and you failed to show the true motivation with your example above. Tino. PS: Votes for a true implementation in current zope instead of the monkey patch? If so, tell me. ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Modifying __bases__
On Fri, May 20, 2005 at 01:48:46PM -0400, Dan Pozmanter wrote: What I aim to do is have the User Object inherit from a custom class (AlienUser). You can do that in two ways off the top of my head: 1) the good way: write a custom UserFolder. You could probably get away with just inheriting from UserFolder and overriding _doAddUser(). 2) the hacky way: monkeypatch User.py to replace SimpleUser with your class. either way the stuff you are interested in is in AccessControl/User.py. -- Paul Winkler http://www.slinkp.com ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Modifying __bases__
You might also be able to do the __bases__ hack with Zope 2.8 (as long as Python 2.3+ allows you to assign to it), as it reimplements ExtensionClass using metaclasses instead of custom C hackery. On Fri, 2005-05-20 at 14:46 -0400, Paul Winkler wrote: On Fri, May 20, 2005 at 01:48:46PM -0400, Dan Pozmanter wrote: What I aim to do is have the User Object inherit from a custom class (AlienUser). You can do that in two ways off the top of my head: 1) the good way: write a custom UserFolder. You could probably get away with just inheriting from UserFolder and overriding _doAddUser(). 2) the hacky way: monkeypatch User.py to replace SimpleUser with your class. either way the stuff you are interested in is in AccessControl/User.py. ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
RE: [Zope] Modifying __bases__
Going with 2.8 sounds like a rather good solution. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Chris McDonough Sent: Friday, May 20, 2005 3:01 PM To: Paul Winkler Cc: zope@zope.org Subject: Re: [Zope] Modifying __bases__ You might also be able to do the __bases__ hack with Zope 2.8 (as long as Python 2.3+ allows you to assign to it), as it reimplements ExtensionClass using metaclasses instead of custom C hackery. On Fri, 2005-05-20 at 14:46 -0400, Paul Winkler wrote: On Fri, May 20, 2005 at 01:48:46PM -0400, Dan Pozmanter wrote: What I aim to do is have the User Object inherit from a custom class (AlienUser). You can do that in two ways off the top of my head: 1) the good way: write a custom UserFolder. You could probably get away with just inheriting from UserFolder and overriding _doAddUser(). 2) the hacky way: monkeypatch User.py to replace SimpleUser with your class. either way the stuff you are interested in is in AccessControl/User.py. ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev ) ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
RE: [Zope] Modifying __bases__
Out of curiosity, I've noticed the word evil attached to patching of various and monkey kinds. Not bad, or unwise, but evil, implying a morality associated with the act. What is morally wrong with modifying live objects in a dynamic language to achieve desired functionality? The idea is I want to modify the zope core in a way that survives version to version, yet does not impose a specific use case on all zope users. -Original Message- From: Tino Wildenhain [mailto:[EMAIL PROTECTED] Sent: Friday, May 20, 2005 2:38 PM To: Dan Pozmanter Cc: Andreas Jung; zope@zope.org Subject: RE: [Zope] Modifying __bases__ Am Freitag, den 20.05.2005, 13:48 -0400 schrieb Dan Pozmanter: Well, when I run it, I am able to do the following: class A: pass class B(A): pass b = B() B.__bases__ = () print B.__bases__ Not so on the version that comes with zope. (B.__bases__ will remain unchanged.) What I aim to do is have the User Object inherit from a custom class (AlienUser). Well, you can just inherit with a class from zopes extension classes. You cannot modify the class bases like this with extension classes. You can work around that like I did with the history (monkey) patch: http://www.zope.org/Members/tino/PatchHistory/view Otherwise it sounds evil and you failed to show the true motivation with your example above. Tino. PS: Votes for a true implementation in current zope instead of the monkey patch? If so, tell me. ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Modifying __bases__
On Fri, May 20, 2005 at 05:10:30PM -0400, Dan Pozmanter wrote: What is morally wrong with modifying live objects in a dynamic language to achieve desired functionality? The idea is I want to modify the zope core in a way that survives version to version, yet does not impose a specific use case on all zope users. I don't want to overgeneralize, but the moral issue I have with monkey-patching is illustrated by an anecdote. Once I was attempting to debug a problem with a core Zope product. It was behaving in a baffling fashion that contradicted what the source code was telling me. It was only during a tedious pdb session that I discovered that a third-party product had monkey-patched the method in question. (This turned out not to be the cause of the problem we were having - but the mystery wasted an hour of my time when I was facing a deadline.) The lesson is: python code may be eminently readable, and on this list we are fond of telling users to use the source - but a monkeypatch in some obscure corner of an add-on package can turn the source code into a big fat lie. That's evil :-) Of course, sometimes it is a necessary (or at least expedient) evil... sometimes you need a hook where there just isn't one and you have no choice but to bash your way in there like a 500-pound gorilla. So, I monkeypatch, and I feel guilty :-) -PW -- Paul Winkler http://www.slinkp.com ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )