Using an interface class for a constant "container" would often be handy but it might be an inappropriate use of interface classes. FTR, I do often put constants in an "interfaces.py" module at module scope (if there are more than one related, sometimes in a dictionary or within a non-interface class statement) in order to not feel I need to create some "constants.py" module. Maybe we could just agree that doing so isn't some sort of violation of intent?
Chris Rossi wrote: > On Fri, Apr 3, 2009 at 7:21 PM, Wichert Akkerman <wich...@wiggy.net> wrote: > >> Previously Chris Rossi wrote: >>> I was wondering if the Zope collective had given any consideration to >>> allowing constants to be defined in interfaces. To be clear, these are >>> constant values that make up the protocol defined by the interface. Just >> to >>> have a concrete example, let's say we're modeling an http response: >>> >>> class IHttpResponse(Interface): >>> """Models an HTTP 1.1 response. >>> """ >>> status = Attribute("HTTP status code for this response.") >>> >>> It might be useful to include in our interface spec what some proper >> values >>> for status code might be and make them available to applications as >> static >>> constants on the interface class. A naive implementer might do something >>> like this: >>> >>> class IHttpResponse(Interface): >>> """Models an HTTP 1.1 response. >>> """ >>> HTTP_OK = "200 Ok" >>> HTTP_NOT_FOUND = "404 Not Found" >>> >>> status = Attribute("HTTP status code for this response.") >> This looks like a poor man's enum. I'ld prefer to have a proper enum >> like thing. >> > > I'm sure you can think of a lot of uses of constant values where an enum > wouldn't be appropriate. I don't know that I'd even use an enum in this > made up example. Some use cases might be covered by an enum, sure, but > that's not really the point here. > > Thanks, > Chris > > > > ------------------------------------------------------------------------ > > _______________________________________________ > Zope-Dev maillist - Zope-Dev@zope.org > http://mail.zope.org/mailman/listinfo/zope-dev > ** No cross posts or HTML encoding! ** > (Related lists - > http://mail.zope.org/mailman/listinfo/zope-announce > http://mail.zope.org/mailman/listinfo/zope ) _______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )