Skip to content

Commit

Permalink
fix type_repr
Browse files Browse the repository at this point in the history
  • Loading branch information
dakk committed Nov 2, 2023
1 parent 1917424 commit eca9dfe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion qlasskit/qlassf.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ def __add__(self, qf2) -> "QlassF":
def truth_table_header(self) -> List[str]:
"""Returns the list of string containing the truth table header"""
header = flatten(list(map(lambda a: a.bitvec, self.args)))
header.extend([sym.name for (sym, retex) in self.expressions[-self.return_size :]])
header.extend(
[sym.name for (sym, retex) in self.expressions[-self.return_size :]]
)
return header

def truth_table(self, max=None) -> List[List[bool]]:
Expand Down
9 changes: 7 additions & 2 deletions qlasskit/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ def const_to_qtype(value: Any):

def type_repr(typ) -> str:
if hasattr(typ, "__name__"):
return typ.__name__
elif len(get_args(typ)) > 0:
if len(get_args(typ)) == 0:
return typ.__name__

args = [type_repr(a) for a in get_args(typ)]
return f"{typ.__name__}[{','.join(args)}]"

elif len(get_args(typ)) > 0: # This is for python = 3.8
args = [type_repr(a) for a in get_args(typ)]
if all([args[0] == a for a in args[1:]]):
return f"Qlist[{args[0]}, {len(args)}]"
Expand Down

0 comments on commit eca9dfe

Please sign in to comment.