Skip to content

Commit

Permalink
feat: updated prettyprint
Browse files Browse the repository at this point in the history
  • Loading branch information
k223kim committed Jun 26, 2024
1 parent 6270cf6 commit ffa8021
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 14 additions & 6 deletions thunder/core/codeutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,20 @@ def prettyprint(
# NOTE: The `class` packagename1_MyContainer will present in `import_ctx` and passed to the compiled function.
# This is taken care of by function `to_printable`.
name = _generate_dataclass_class_name(x)
instance_repr = str(x)
parens_idx = instance_repr.find("(")
call_repr = instance_repr[
parens_idx:
] # only keep the construction part of the repr (as we will use our generated name)
return m(f"{name + call_repr}")
call_repr_str = ""
for k, v in x.__dict__.items():
try:
call_repr_str += f"{k}={v.name},"
except:
call_repr_str += f"{k}={v},"
# pass
# instance_repr = str(x)
# parens_idx = instance_repr.find("(")
# call_repr = instance_repr[
# parens_idx:
# ] # only keep the construction part of the repr (as we will use our generated name)
return m(f"{name}({call_repr_str})")
# return m(f"{name}(t=x)")

# Handles objects that this doesn't know how to serialize as a string
return m(f"(object of type {print_type(type(x), with_quotes=False)})")
Expand Down
2 changes: 2 additions & 0 deletions thunder/core/proxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,15 @@ def __init__(self, name: str | None = None, *, prefix: None | str = None, histor
@property
def name(self) -> str:
return self._name
# return f"{type(self).__name__} {self._name}"

def replace_name(self, name: str | None = None):
"""Return a copy of this proxy with the given name."""
return self.__class__(name=name)

def __repr__(self) -> str:
return f"<{type(self).__name__} {self.name}>"
# return f"{self.name}"

def type_string(self) -> str:
return "Any"
Expand Down

0 comments on commit ffa8021

Please sign in to comment.