Skip to content

Commit

Permalink
Support None
Browse files Browse the repository at this point in the history
  • Loading branch information
katsumiok committed Oct 22, 2023
1 parent 9b8a697 commit 512bcd9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pyaskit/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
code,
record,
ref,
none,
IntType,
FloatType,
StringType,
Expand All @@ -22,5 +23,6 @@
UnionType,
CodeType,
RecordType,
NoneType,
Type,
)
2 changes: 2 additions & 0 deletions pyaskit/types/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ def convert_type(x):
# return t.literal(*get_args(x))
elif origin is dict:
return t.record(convert_type(args[0]), convert_type(args[1]))
elif origin is None:
return t.none
return x
3 changes: 3 additions & 0 deletions pyaskit/types/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ def visit_ref(self, type: t.RefType):
self.type_defs[type.name] = None
self.type_defs[type.name] = type.access().accept(self)
return type.name

def visit_none(self, type):
return "null"


# export function generateSchema<T>(type: any): string {
Expand Down
3 changes: 3 additions & 0 deletions pyaskit/types/type_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,6 @@ def visit_record(self, type):

def visit_ref(self, type):
return type.name

def visit_none(self, type):
return "None"
14 changes: 14 additions & 0 deletions pyaskit/types/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def visit_record(self, type):

def visit_ref(self, type):
raise NotImplementedError("visit_ref method not implemented")

def visit_none(self, type):
raise NotImplementedError("visit_none method not implemented")


class Type:
Expand All @@ -52,6 +55,17 @@ def accept(self, visitor):
raise NotImplementedError("accept method not implemented")


class NoneType(Type):
def validate(self, value):
return value is None

def accept(self, visitor):
return visitor.visit_none(self)


none = NoneType()


class CodeType(Type):
def __init__(self, language: builtins.str) -> None:
self.language = language
Expand Down

0 comments on commit 512bcd9

Please sign in to comment.