Ok, If I attach an item_type to the the list, I do not think I will able to use the native Python list, and should use a subclass instead. It is a bit heavyweight, especially when the intent of the use of the interface was documentation.
List and generators are very common in Python and are expressed in very few and clear characters, I thought there would be a shorter way to document their interfaces. Thank you, On Mon, Nov 8, 2010 at 2:24 PM, Tres Seaver <tsea...@palladion.com> wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On 11/08/2010 04:40 AM, Jean-Daniel wrote: > > Hello, > > > > I have two objects which interoperate to solve a sudoku: the Sudoku class > > and a vector (a list actually) of generator functions. The Sudoku > interface > > is simple to write as it requires three functions and an attribute. > > > > class ISudoku: > > > > board = Attribute() > > > > def free(col, line): > > "frees the slot at position col, line" > > > > def set(col, line, value): > > "Sets the value in the slot at position col, line" > > > > def candidates(col, line): > > "Returns the candidate digits for the slot at position col,line" > > > > > > But how to express "vector of generator functions" with Zope interfaces? > I > > want to express the possibility to access the vector object with > > the [n] index notation, and this returns a function returning a > generator > > (an object with an iter and next function). > > > > Thank you for your help, > > > > > > PS: the vector of generator functions is the input of the algorithm > called > > "conjoin", used to solve the eight queen problem and knight's tour > problem. > > It is described in the Python sources > > (Python-2.6.5/Lib/test/test_generators.py). > > > > PPS: I say vector instead of list even when the vector is a list, because > > "list" usually implies the possibility to append elements dynamically > which > > is not pertinent in this problem. The length of the vector won't change > and > > is equal to the number of slots on a sudoku board. > > > I would specify the contracts omething like so:: > > > class IVector(Interface): > > item_type = Attribute(u"Interface of items.") > > def __len__(): > """ Fixed length of vector. > """ > > def __getitem__(index): > """ Return the 'index'th item. > > Items conform to 'item_type'. > > 'index' must be an integer between 0 and __len__() - 1, > else raise IndexError. > """ > > class IIterable(Interface): > > def __iter__(): > """ Return an iterator for this object. > """ > > > > > - -- > =================================================================== > Tres Seaver +1 540-429-0999 tsea...@palladion.com > Palladion Software "Excellence by Design" http://palladion.com > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.10 (GNU/Linux) > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ > > iEYEARECAAYFAkzX+ggACgkQ+gerLs4ltQ7WQwCeNu4lF+WysIjSYM86EjMhoPFH > 9ZsAnRB7T4Pz+bIVeVYxHbvRYaqN6iE7 > =U5bo > -----END PGP SIGNATURE----- > > _______________________________________________ > Zope-Dev maillist - Zope-Dev@zope.org > https://mail.zope.org/mailman/listinfo/zope-dev > ** No cross posts or HTML encoding! ** > (Related lists - > https://mail.zope.org/mailman/listinfo/zope-announce > https://mail.zope.org/mailman/listinfo/zope ) >
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org https://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - https://mail.zope.org/mailman/listinfo/zope-announce https://mail.zope.org/mailman/listinfo/zope )