Re: [Zope3-Users] Dynamic Typing: Are checks on interface compliance possible?
Hi Reinhold, In addition to verifyClass and verifyObject, I am developing a module for doing realtime typechecks. I am using a first version of it for one application and it works great. I have made a proposal and readme for it, which I have attached. Is this what you are looking for? Marc Op 18-5-2006 8:23, Reinhold Strobl schreef: Hi, what I am looking for is something like PyChecker for Zope interfaces. I mean PyChecker aims to address the benefit of static typed languages and their compile-time checkings. In Zope, there is no forced interface compliance. But is there a possibility or program, which can check this? Thanks! ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users TypeCheck of Interfaces Status IsProposal Author Marc Rijken Problem/Proposal/Goals In interfaces the behaviour of methods and attributes is been described. It would be nice if this desciption could be used for checking the behaviour of implemented methods/attributes. In fact, my proposal consist of: 1. describe at the level of the implemented method/attribute the interface and not on the class level, so it is always clear which interface describes the intended behaviour of the implemented method/attribute 2. use the docstring of the interface to extend the docstring of the method and put in a reference to the interface automatically based on 1. 3. use the interface for checking the behaviour of the method/attribute on runtime. Proposed Solution 1. use 'implement' at the method level in stead of 'implements' at the class level. I.e.:: class Test(object): @implement(ITest) def add(self, x, y): return x+y @implement(ITest) def multiply(self, x, y): return x*y @implementGetter(ITest['at']) def _getAt(self): return self.i @implementSetter(ITest['at']) def _setAt(self, value): self.i = value at = property(_getAt, _setAt) in stead of:: class Test(object): implements(ITest) def add(self, x, y): return x+y def multiply(self, x, y): return x*y def _getAt(self): return self.i def _setAt(self, value): self.i = value at = property(_getAt, _setAt) The decorators `implement`, `implementGetter` and `implementSetter` acts like implements. 2. `implement` changs also the docstring of the implemented method. Ie:: class ITest(Interface): def add(x, y): """add two parameters""" def multiply(x, y): """multiply two parameters""" class Test(object): @implement(ITest) def add(self, x, y): return x+y @implement(ITest) def multiply(self, x, y): """a test implementation""" return x*y would give the following docstring for Test.add.__doc__:: Interface ITest, method add add two parameters and would give the following docstring for Test.mulitply.__doc__:: Interface ITest, method multiply multiply two parameters a test implementation 3. In order to use the interface for typechecking, I propose to use the TypeCheck module (see http://oakwinter.com/code/typecheck/). This can be used easely, when 'implement' works like 'accepts' and 'returns'. The parameters for accepts and returns has to be added to the interface. For example:: class ITest(Interface): @accepts(int, int) @returns(str) def add(x, y): """add two parameters""" @accepts(float, float) @returns(float) def multiply(x, ysdx): """multiply two parameters""" In accepts or returns you can give any type or class. The parameter of the method will be checked for beiing an instance of that type or class. But it is also convenient when it is possible to give the interface which has to be implemented by the parameter. So the parameter is checked like in ITest.providedBy(par1).:: class ITest2(Interface): @accepts(ITest, ITest) @returns(ITest) def add(x, y): """add two parameters""" This usage c
[Zope3-Users] Re: Dynamic Typing: Are checks on interface compliance possible?
Thanks a lot, I think your approach could gain great popularity! ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] [ANN] win32-trunk-pyds
Hello *, I just put the compiled pyd's for win32 users to http://www.zope.org/Products/Zope3/, into a relase called 'Trunk'. -- Best regards, Adam mailto:[EMAIL PROTECTED] -- Quote of the day: I pronounce it as certain that there was never a truly great man that was not at the same time truly virtuous. - Benjamin Franklin ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Re: Dynamic Typing: Are checks on interface compliance possible?
Reinhold Strobl wrote: > I think your approach could gain great popularity! Just wondering, what is the matter with PEP 245? According to it, "This PEP has not yet been discussed on python-dev", which is untrue, but it's been a while. ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Dynamic Typing: Are checks on interface compliance possible?
On Thursday 18 May 2006 02:29, Michael Howitz wrote: > Reinhold Strobl wrote: > > Hi, > > > > what I am looking for is something like PyChecker for Zope interfaces. I > > mean PyChecker aims to address the benefit of static typed languages and > > their compile-time checkings. > > > > In Zope, there is no forced interface compliance. But is there a > > possibility or program, which can check this? > > Hi, > > you should have a look at zope.interface.verify. With verifyClass and > verifyObject you can check the interface compliance for classes and > objects. In addition there is the FieldProperty class, which can be used to enforce a value. I have recently started to use it all the time. I really like it too. Eventually you probably would also want something that enforces the entire interface on the class, including invariants. That would be something interesting to think about. Regards, Stephan -- Stephan Richter CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student) Web2k - Web Software Design, Development and Training ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Dynamic Typing: Are checks on interface compliance possible?
Stephan Richter wrote: > In addition there is the FieldProperty class, which can be used to enforce a > value. I have recently started to use it all the time. I really like it too. It also sets the attributes to the default values inside the tests, taking them from the interface definition instead of the class definition.. class MyObject: implements(IMyObject) what = 42 vs. class IMyObject(Interface): what = Int(title=u"Whatever",default=42) class MyObject: """ >>> from zope.interface.verify import verifyClass >>> verifyClass(IMyObject, MyObject) True Try changing the attributes: >>> obj = MyObject() >>> obj.what 42 >>> obj.what=56 >>> obj.what 56 """ implements(IMyObject) what = FieldProperty(IMyObject['what']) ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] Re: [Zope3-dev] [ANN] win32-trunk-pyds
On Thursday 18 May 2006 03:30, Adam Groszer wrote: > I just put the compiled pyd's for win32 users to > http://www.zope.org/Products/Zope3/, into a relase called 'Trunk'. Adam, thanks for doing this. This is fantastic! Regards, Stephan -- Stephan Richter CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student) Web2k - Web Software Design, Development and Training ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] Lost in security proxy land... Was: zope.ManageContent Permission on field descriptions?
Hi, The answer to my problem described in my last posts is SecurityProxy. I found this very insightful IRC chatlog between Jim Fulton and Martijn Faassen on #zope3-dev. It is available on http://zope3.pov.lt/irclogs/%23zope3-dev.2005-09-08.log.html The conversation starts with Martijn saying "I'm currently lost in security proxy land". Worth a read. - Andreas ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] zope.schema.Object and custom widgets in formlib
hi there I am having trouble getting form's generated for zope.schema.Object. After doing some more reading it looks like I should be using formlib instead of zope.app.form.browser.add.AddView and zope.app.form.browser.editview.EditView (my new code will be at the bottom) Which is fine because I was really having trouble getting zope.schema.Object to work properly. Of course, now I am running into the same basic problem with formlib. It looks like I need to specify some sort of custom widget for my zope.schema.Object. If I don't I get the same ComponentLookupError I was getting with the old system. I tried the zope.app.form.CustomWidgetFactory, and that actually got that part of the form to show up but it didn't work right. If someone could tell me what I should be doing that would be great. Also one other kinda bizarre thing, in my formlib form all the button text and messages where in German (I think, my German is a little rusty). An aside... I have been really surprised by the lack of other people having the same problems or working examples else where. I think I'm trying to do something very basic that would come up in lots of applications. This makes me think that I'm going about this the wrong way, or the solution is very simple and I'm just being too dense to get it. So basically, if anyone out there has some commentary on my approach to this problem I would really appreciate it. thanks. -jachin # -=interfaces.py=- from zope.interface import Interface from zope.schema import TextLine, Int, Object class IStreetAddress(Interface): """A street address""" street = TextLine( title=u"street", description=u"", required=False) class IABookEntry(Interface): """An address book entry""" streetAddress = Object( schema=IStreetAddress, title=u"Street Address", description=u"", required=False) firstName = TextLine( title=u"First Name", description=u"", required=False) # -=entry.py=- from zope.interface import implements from zope.formlib import form from zope.schema.fieldproperty import FieldProperty from zope.app.form import CustomWidgetFactory from zope.app.form.browser import ObjectWidget from persistent import Persistent from interfaces import IStreetAddress from interfaces import IABookEntry class StreetAddress(Persistent): """The Street Address object.""" implements(IStreetAddress) class ABookEntry(Persistent): """The Address Book Entry object.""" implements(IABookEntry) streetAddress = StreetAddress firstName = u"" class ABookEntryEditView(form.EditForm): form_fields = form.Fields(IABookEntry) form_fields["streetAddress"].custom_widget = what should go here? http://namespaces.zope.org/zope"; xmlns:browser="http://namespaces.zope.org/browser";> ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users