From 85fd7ef3ad80ee3eeec7fbcd18d47c7e8d5c04e8 Mon Sep 17 00:00:00 2001 From: Colin Gravill Date: Thu, 1 Jul 2021 12:14:49 +0100 Subject: [PATCH] Drop classproperty, just "declare" attributes in advance alternative from @acl33 https://github.com/microsoft/knossos-ksc/issues/888#issuecomment-869596450 --- src/python/ksc/type.py | 43 +++++++++++++----------------------------- 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/src/python/ksc/type.py b/src/python/ksc/type.py index 192501120..c878d2a99 100644 --- a/src/python/ksc/type.py +++ b/src/python/ksc/type.py @@ -6,16 +6,6 @@ class KSTypeError(RuntimeError): pass -# TODO: decide if we want to keep this approach, or move to module level functions -# https://github.com/microsoft/knossos-ksc/issues/888 -class classproperty(object): - def __init__(self, getter): - self.getter = getter - - def __get__(self, _, owner): - return self.getter(owner) - - class Type: """ Knossos AST node type. Grouped into @@ -26,6 +16,12 @@ class Type: LM S T """ + String: "Type" + Float: "Type" + Integer: "Type" + Bool: "Type" + Any: "Type" + node_kinds = { "Tensor": 2, # two children (Rank, Type) "Tuple": -1, # special case two or more @@ -58,26 +54,6 @@ def __init__(self, kind, children=[]): ################ ## Constructors - @classproperty - def String(cls) -> "Type": - return Type("String") - - @classproperty - def Float(cls) -> "Type": - return Type("Float") - - @classproperty - def Integer(cls) -> "Type": - return Type("Integer") - - @classproperty - def Bool(cls) -> "Type": - return Type("Bool") - - @classproperty - def Any(cls) -> "Type": - return Type("Any") - @staticmethod def Tensor(rank, elem_type): """ @@ -371,3 +347,10 @@ def shape_type(t: Type) -> Type: return Type.Tensor(t.tensor_rank, shape_type(t.tensor_elem_type)) raise NotImplementedError + + +Type.String = Type("String") +Type.Float = Type("Float") +Type.Integer = Type("Integer") +Type.Bool = Type("Bool") +Type.Any = Type("Any")