Skip to content
This repository was archived by the owner on Sep 9, 2026. It is now read-only.

Commit a70142a

Browse files
author
anna-charlotte
committed
fix: set _console instead of initializing new one everytime in __str__
Signed-off-by: anna-charlotte <charlotte.gerhaher@jina.ai>
1 parent 6ba4eff commit a70142a

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎docarray/base_document/document.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class BaseDocument(BaseModel, PlotMixin, ProtoMixin, AbstractDocument, BaseNode)
1818
"""
1919

2020
id: ID = Field(default_factory=lambda: parse_obj_as(ID, os.urandom(16).hex()))
21+
_console: rich.console.Console = rich.console.Console()
2122

2223
class Config:
2324
json_loads = orjson.loads
@@ -37,8 +38,7 @@ def _get_field_type(cls, field: str) -> Type['BaseDocument']:
3738
return cls.__fields__[field].outer_type_
3839

3940
def __str__(self):
40-
console = rich.console.Console()
41-
with console.capture() as capture:
42-
console.print(self)
41+
with self._console.capture() as capture:
42+
self._console.print(self)
4343

4444
return capture.get().strip()

0 commit comments

Comments
 (0)