<div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div><div>typing.NamedTuple was already mentioned in this discussion, I just would like to add few comments:<br></div><br>1. I think that changing Python syntax to support declarative classes is not a realistic option in nearby future.<br></div>In contrast, there is an existing syntax change - variable annotations - that can be actively experimented with.<br></div>Variable annotations are designed to play well with metaclass machinery, for example, they will respect<br>__prepare__ method, if it injects __annotations__ as a custom mapping, etc.<br><br></div>2. Possible strategy for declarative classes could be developing independent *composable* mixins/traits:<br><br></div>  @comparable<br></div>  @pickleable<br></div>  class MyClass:<br></div>      x: int<br></div>      y: int<br><br></div>or<br><br></div>  class MyClass(Comparable, Pickleable):<br></div>      x: int<br></div>      y: int<br><br></div>The problem with the second approach is that it can lead to metaclass conflicts. A possible solution will<br></div>be to provide a standard metaclass for mixins in stdlib.<br><br></div>3. Composability could be a problem if only normal variable assignments are used: after one mixin transforms the class,<br></div>the original declarations are lost. Simple possible solution would be to agree that mixins should *not* modify<br></div><div>__annotations__, only __dict__. Currently, PEP 484 and PEP 526 specify that preferable use of annotations is type<br></div><div>declarations. However, I think this can be generalized to just declarations. For example, by providing a special typing<br>construct that will allow additional info apart from type:<br><br></div><div>  def large(val):<br></div><div>      return val > 42<br></div><div><br></div><div>  @comparable<br></div><div>  @pickleable<br></div><div>  class MyClass<br>      x: Spec(int, validator=large)</div><div>      y: Spec(List[int], default_factory=list)<br><br><br></div><div>--<br></div><div>Ivan<br><br><br></div><div></div></div>