
+1 for static type checking and avoiding inheritance in the syntax. My interest comes from working on transpiling python, including sealed classes to other statically typed languages. I've used syntax such as this in one of my earlier projects with good success: ``` @sealed class Node: EXPRESSION = Expression STATEMENT = Statement @sealed class Expression: NAME = Name OPERATION = Operation @sealed class Statement: ASSIGNMENT = Assignment ``` Will need some metadata (another decorator?) to distinguish these class members from other class members that have nothing to do with sealed classes. This way, the static checker knows how to compute the exhaustive list of permitted classes when checking a match statement. -Arun On Thu, May 20, 2021 at 8:07 PM <asafspades@gmail.com> wrote:
It seems worth noting that you can already use static types that are de facto sealed using @final (PEP 591):
@final class Value(Node): ... @final class BinOp(Node): ... @final class UnOp(Node): ... AnyNode = Union[Value, BinOp, UnOp]
Clearly the Sealed proposal would be easier to read and write, and probably has other advantages I haven't fully thought through (e.g. having an actual runtime class, or doing runtime enforcement unlike @final). _______________________________________________ Typing-sig mailing list -- typing-sig@python.org To unsubscribe send an email to typing-sig-leave@python.org https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: arun.sharma@gmail.com