Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4fb3bde

Browse files
iftenneyLIT team
authored andcommitted
Pretty-printing of Model objects
PiperOrigin-RevId: 629571604
1 parent a5265a4 commit 4fb3bde

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

lit_nlp/api/model.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,18 @@ def description(self) -> str:
8989
"""
9090
return inspect.getdoc(self) or ''
9191

92+
def __str__(self) -> str:
93+
classname = self.__class__.__module__ + '.' + self.__class__.__qualname__
94+
indented_description = ' ' + self.description().replace('\n', '\n ')
95+
return f'{classname}(...):\n{indented_description}'
96+
97+
def _repr_pretty_(self, p, cycle):
98+
"""Pretty-printing for IPython environments, both notebooks and repl."""
99+
if not cycle:
100+
p.text(str(self))
101+
else:
102+
p.text('...')
103+
92104
@classmethod
93105
def init_spec(cls) -> Optional[Spec]:
94106
"""Attempts to infer a Spec describing a Model's constructor parameters.

0 commit comments

Comments
 (0)