Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #33 from SebastienLavoie/expose-declared-types
Browse files Browse the repository at this point in the history
Add private field to access declared types
  • Loading branch information
jspahrsummers authored Feb 29, 2020
2 parents 0c33d30 + c4bb581 commit e0f3724
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions adt/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ def deconstructCase(self, value: Tuple[Any, ...],
assert len(value) == len(self._types)
return callback(*value)

def getTypes(self) -> Any:
return self._types

def __repr__(self) -> str:
typeString = ', '.join((str(t) for t in self._types))
return f'Case[{typeString}]'
Expand All @@ -34,6 +37,9 @@ def constructCase(self, arg: _T) -> _T:
def deconstructCase(self, value: _T, callback: Callable[[_T], _U]) -> _U:
return callback(value)

def getTypes(self) -> Any:
return self._argType

def __repr__(self) -> str:
return f'Case[{self._argType}]'

Expand All @@ -48,6 +54,9 @@ def constructCase(self) -> None:
def deconstructCase(self, value: None, callback: Callable[[], _T]) -> _T:
return callback()

def getTypes(self) -> None:
return None

def __getitem__(self, params: Union[None, Type[Any], Tuple[Type[Any], ...]]
) -> AnyConstructor:
if params is None:
Expand Down
2 changes: 2 additions & 0 deletions adt/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def adt(cls):
cls._Key = Enum( # type: ignore
'_Key', list(caseConstructors.keys()))

cls._types = list(x.getTypes() for x in list(caseConstructors.values()))

_installInit(cls)
_installRepr(cls)
_installStr(cls)
Expand Down

0 comments on commit e0f3724

Please sign in to comment.