Skip to content

Commit

Permalink
Drop classproperty, just "declare" attributes in advance
Browse files Browse the repository at this point in the history
alternative from @acl33
#888 (comment)
  • Loading branch information
cgravill committed Jul 1, 2021
1 parent 6095eb2 commit 85fd7ef
Showing 1 changed file with 13 additions and 30 deletions.
43 changes: 13 additions & 30 deletions src/python/ksc/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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")

0 comments on commit 85fd7ef

Please sign in to comment.