Skip to content

Commit 33264f7

Browse files
author
Christopher Doris
committed
simplify display of python objects
1 parent 8d255be commit 33264f7

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

src/Py.jl

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -175,28 +175,17 @@ function Base.show(io::IO, x::Py)
175175
end
176176

177177
function Base.show(io::IO, ::MIME"text/plain", o::Py)
178-
hasprefix = get(io, :typeinfo, Any) != Py
179178
if pyisnull(o)
180-
if hasprefix
181-
printstyled(io, "Python NULL", bold=true)
182-
else
183-
print(io, "NULL")
184-
end
185-
return
186-
elseif pyisnone(o)
187-
if hasprefix
188-
printstyled(io, "Python None", bold=true)
189-
else
190-
print(io, "None")
191-
end
192-
return
179+
str = "NULL"
180+
else
181+
str = pyrepr(String, o)
193182
end
194-
h, w = displaysize(io)
195-
compact = get(io, :compact, false)
196-
str = pyrepr(String, o)
183+
hasprefix = (get(io, :typeinfo, Any) != Py)::Bool
184+
compact = get(io, :compact, false)::Bool
197185
multiline = '\n' in str
198-
prefix = hasprefix ? compact ? "Py:$(multiline ? '\n' : ' ')" : "Python $(pytype(o).__name__):$(multiline ? '\n' : ' ')" : ""
199-
printstyled(io, prefix, bold=true)
186+
prefix = hasprefix ? compact ? "Py:$(multiline ? '\n' : ' ')" : "Python:$(multiline ? '\n' : ' ')" : ""
187+
print(io, prefix)
188+
h, w = displaysize(io)
200189
if get(io, :limit, true)
201190
h, w = displaysize(io)
202191
h = max(h-3, 5) # use 3 fewer lines to allow for the prompt, but always allow at least 5 lines

0 commit comments

Comments
 (0)