Skip to content

Commit

Permalink
Generate string from scratch in __repr__
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacna committed Jan 25, 2022
1 parent 7b56c23 commit 439bf1a
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions cdp_backend/pipeline/transcript_model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import re
from dataclasses import dataclass
from datetime import datetime
from typing import List, Optional
Expand Down Expand Up @@ -218,12 +217,24 @@ class Transcript:
sentences: List[Sentence]
annotations: Optional[TranscriptAnnotations] = None

def __str__(self) -> str:
string = repr(self)
cleaned = re.sub(
r"sentences=\[.*\], annotations", "sentences=[...], annotations", string
)
return cleaned
def __repr__(self) -> str:
output = "Transcript("

# Use vars to maintain subclassing
for k, v in vars(self).items():
# Truncate sentences
if k == "sentences":
output += f"{k}=[...] (n={len(v)}), "

# Add quotes for strings
elif type(v) == str:
output += f"{k}='{v}', "

else:
output += f"{k}={v}, "

# Remove last comma and space and close parentheses
return output[:-2] + ")"


###############################################################################
Expand Down

0 comments on commit 439bf1a

Please sign in to comment.