Hello,<br><br>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&#39;s say we&#39;re modeling an http response:<br>
<br><span style="font-family: courier new,monospace;">class IHttpResponse(Interface):</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    &quot;&quot;&quot;Models an HTTP 1.1 response.</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    &quot;&quot;&quot;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    status = Attribute(&quot;HTTP status code for this response.&quot;)</span><br>
<br>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:<br>
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">class IHttpResponse(Interface):</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    &quot;&quot;&quot;Models an HTTP 1.1 response.</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    &quot;&quot;&quot;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    HTTP_OK = &quot;200 Ok&quot;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    HTTP_NOT_FOUND = &quot;404 Not Found&quot;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    status = Attribute(&quot;HTTP status code for this response.&quot;)</span><br>

<br>As you can see, the HTTP_OK and HTTP_NOT_FOUND constants are conceptually part of the interface--they help define our contract for http responses.  We might expect to then be able to do something like this in application code:<br>
<br><span style="font-family: courier new,monospace;">response.status = IHttpResponse.HTTP_OK</span><br><br>Of course, if you try this currently, Interface will complain:<br><br><span style="font-family: courier new,monospace;">InvalidInterface: Concrete attribute, HTTP_OK</span><br>
<br>I did do some poking around in the source code and in the documentation, such as it is, and didn&#39;t see anything like constants in interfaces, but it&#39;s possible this use case has already been addressed somehow and I am just ignorant of how, in which case, my apologies, and thanks for telling me the already accepted way to do this.<br>
<br>If this hasn&#39;t been done yet, I can envision doing something like:<br><br><span style="font-family: courier new,monospace;">from zope.interface import Constant</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">class IHttpResponse(Interface):</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    &quot;&quot;&quot;Models an HTTP 1.1 response.</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    &quot;&quot;&quot;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
    HTTP_OK = Constant(&quot;200 Ok&quot;, &quot;An HTTP Ok response.&quot;)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
    HTTP_NOT_FOUND = Constant(&quot;404 Not Found&quot;, &quot;An HTTP Not Found response&quot;)</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
    status = Attribute(&quot;HTTP status code for this response.&quot;)</span><br><br>Using descriptors, the results could be both static and immutable.<br><br>Does this seem useful to anyone besides me?  Anyone who&#39;s done much Java programming will recognize that I did not have an original idea here.  <br>
<br>If there is a general buy in, I would be happy to attempt an implementation and submit a patch.<br><br>Thanks,<br>Chris<br><br>PS I did find a hack that will let you accomplish this, although it is a hack rather than a supported feature of the component architecture:<br>
<br><span style="font-family: courier new,monospace;">class IHttpResponse(Interface):</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    &quot;&quot;&quot;Models an HTTP 1.1 response.</span><br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;">    &quot;&quot;&quot;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    status = Attribute(&quot;HTTP status code for this response.&quot;)</span><br style="font-family: courier new,monospace;">

<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">IHttpResponse.HTTP_OK = &quot;200 Ok&quot;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">IHttpResponse.HTTP_NOT_FOUND = &quot;404 Not Found&quot;</span><br style="font-family: courier new,monospace;">


<br style="font-family: courier new,monospace;">

<span style="font-family: courier new,monospace;"></span>Because the interface class is decorated after the type is instantiated, the InvalidInterface check is avoided.<br><br>