Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display for pytype in Pluto notebooks #101

Closed
icweaver opened this issue Jan 24, 2022 · 3 comments
Closed

Display for pytype in Pluto notebooks #101

icweaver opened this issue Jan 24, 2022 · 3 comments

Comments

@icweaver
Copy link

icweaver commented Jan 24, 2022

pytype seems to throw the following for me in a Pluto notebook:

using PythonCall

x_py = pylist([1, 2, 3])
# x_py = Python list: [1, 2, 3]

pytype(x_py)
Failed to show value:

MethodError: no method matching show(::IOContext{IOBuffer}, ::Nothing, ::PythonCall.Py)

Closest candidates are:

show(::IO, !Matched::AbstractString, ::Any) at ~/julia-1.7.1/share/julia/base/multimedia.jl:111
show(::IO, !Matched::MIME{Symbol("text/csv")}, ::PythonCall.Py) at ~/.julia/packages/PythonCall/59kNC/src/Py.jl:266
show(::IO, !Matched::MIME{Symbol("text/csv")}, ::Any) at ~/julia-1.7.1/share/julia/stdlib/v1.7/DelimitedFiles/src/DelimitedFiles.jl:829
...
    1. show_richest(::IOContext{IOBuffer}, ::Any)@PlutoRunner.jl:1019
    2. var"#sprint_withreturned#54"(::IOContext{Base.DevNull}, ::Int64, ::typeof(Main.PlutoRunner.sprint_withreturned), ::Function, ::PythonCall.Py)@PlutoRunner.jl:954
    3. format_output_default(::Any, ::Any)@PlutoRunner.jl:862
    4. var"#format_output#42"(::IOContext{Base.DevNull}, ::typeof(Main.PlutoRunner.format_output), ::Any)@PlutoRunner.jl:879
    5. formatted_result_of(::Base.UUID, ::Bool, ::Vector{String}, ::Nothing, ::Module)@PlutoRunner.jl:785
    6. top-level scope@none:1

while printing to plain text looks to work fine I think:

println(pytype(x_py)) # <class 'list'>

albeit the display is slightly different than just running it directly in the REPL:

julia> using PythonCall
    
julia> x_py = pylist([1, 2, 3])
Python list: [1, 2, 3]

julia> pytype(x_py)
Python type: <class 'list'>

Loving all the new updates by the way!

@cjdoris
Copy link
Collaborator

cjdoris commented Jan 24, 2022

Thanks! It's a bug caused by the fact that x.__repr__() doesn't work when x is a type, you need to do type(x).__repr__(x) instead. Fixed on main branch.

@cjdoris cjdoris closed this as completed Jan 24, 2022
@icweaver
Copy link
Author

Wow, you are insanely fast

dog-race

Thanks so much for the quick fix, it works beautifully!

@cjdoris
Copy link
Collaborator

cjdoris commented Jan 24, 2022

Haha, you were just lucky to catch me while I was already looking at PythonCall!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants