Skip to content

Commit 90ad374

Browse files
committed
Fix text representation
1 parent a0c7d16 commit 90ad374

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

js/src/messaging.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ export type RawData = {
4848
*
4949
*
5050
* The result can contain multiple types of data, such as text, images, plots, etc. Each type of data is represented
51-
* as a string, and the result can contain multiple types of data. The text representation is always present, and
52-
* the other representations are optional.
51+
* as a string, and the result can contain multiple types of data. The display calls don't have to have text representation,
52+
* for the actual result the representation is always present for the result, the other representations are always optional.
5353
*/
5454
export class Result {
5555
/**
56-
* Text representation of the result. Always present.
56+
* Text representation of the result.
5757
*/
58-
readonly text: string
58+
readonly text?: string
5959
/**
6060
* HTML representation of the data.
6161
*/

python/e2b_code_interpreter/models.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@ class Result:
3838
The result is similar to the structure returned by ipython kernel: https://ipython.readthedocs.io/en/stable/development/execution.html#execution-semantics
3939
4040
The result can contain multiple types of data, such as text, images, plots, etc. Each type of data is represented
41-
as a string, and the result can contain multiple types of data. The text representation is always present, and
42-
the other representations are optional.
41+
as a string, and the result can contain multiple types of data. The display calls don't have to have text representation,
42+
for the actual result the representation is always present for the result, the other representations are always optional.
4343
4444
The class also provides methods to display the data in a Jupyter notebook.
4545
"""
4646

47-
text: str
48-
"Text representation of the result. Always present."
47+
text: Optional[str] = None
4948
html: Optional[str] = None
5049
markdown: Optional[str] = None
5150
svg: Optional[str] = None
@@ -68,7 +67,7 @@ def __init__(self, is_main_result: bool, data: [MIMEType, str]):
6867
self.is_main_result = is_main_result
6968
self.raw = copy.deepcopy(data)
7069

71-
self.text = data.pop("text/plain")
70+
self.text = data.pop("text/plain", None)
7271
self.html = data.pop("text/html", None)
7372
self.markdown = data.pop("text/markdown", None)
7473
self.svg = data.pop("image/svg+xml", None)
@@ -111,79 +110,79 @@ def formats(self) -> Iterable[str]:
111110

112111
return formats
113112

114-
def __str__(self) -> str:
113+
def __str__(self) -> Optional[str]:
115114
"""
116115
Returns the text representation of the data.
117116
118117
:return: The text representation of the data.
119118
"""
120119
return self.text
121120

122-
def _repr_html_(self) -> str:
121+
def _repr_html_(self) -> Optional[str]:
123122
"""
124123
Returns the HTML representation of the data.
125124
126125
:return: The HTML representation of the data.
127126
"""
128127
return self.html
129128

130-
def _repr_markdown_(self) -> str:
129+
def _repr_markdown_(self) -> Optional[str]:
131130
"""
132131
Returns the Markdown representation of the data.
133132
134133
:return: The Markdown representation of the data.
135134
"""
136135
return self.markdown
137136

138-
def _repr_svg_(self) -> str:
137+
def _repr_svg_(self) -> Optional[str]:
139138
"""
140139
Returns the SVG representation of the data.
141140
142141
:return: The SVG representation of the data.
143142
"""
144143
return self.svg
145144

146-
def _repr_png_(self) -> str:
145+
def _repr_png_(self) -> Optional[str]:
147146
"""
148147
Returns the base64 representation of the PNG data.
149148
150149
:return: The base64 representation of the PNG data.
151150
"""
152151
return self.png
153152

154-
def _repr_jpeg_(self) -> str:
153+
def _repr_jpeg_(self) -> Optional[str]:
155154
"""
156155
Returns the base64 representation of the JPEG data.
157156
158157
:return: The base64 representation of the JPEG data.
159158
"""
160159
return self.jpeg
161160

162-
def _repr_pdf_(self) -> str:
161+
def _repr_pdf_(self) -> Optional[str]:
163162
"""
164163
Returns the PDF representation of the data.
165164
166165
:return: The PDF representation of the data.
167166
"""
168167
return self.pdf
169168

170-
def _repr_latex_(self) -> str:
169+
def _repr_latex_(self) -> Optional[str]:
171170
"""
172171
Returns the LaTeX representation of the data.
173172
174173
:return: The LaTeX representation of the data.
175174
"""
176175
return self.latex
177176

178-
def _repr_json_(self) -> dict:
177+
def _repr_json_(self) -> Optional[dict]:
179178
"""
180179
Returns the JSON representation of the data.
181180
182181
:return: The JSON representation of the data.
183182
"""
184183
return self.json
185184

186-
def _repr_javascript_(self) -> str:
185+
def _repr_javascript_(self) -> Optional[str]:
187186
"""
188187
Returns the JavaScript representation of the data.
189188

0 commit comments

Comments
 (0)