JuliaPy / JuliaPy/PyCall.jl

Misalignment of first line in multiline show of PyObject

Offen
#888 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Julia
Sterne
1.5k
Forks
186
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

PyObjects whose pystring method returns a multiline string have their first row misaligned when shown. For example

```julia
using PyCall
qiskit = pyimport("qiskit")
qc = qiskit.QuantumCircuit(1)
qc.x(0)
qc.draw()
```
gives
```
PyObject ┌───┐
q_0: ┤ X ├
└───┘
```

A fix would be to replace
```julia
function show(io::IO, o::PyObject)
print(io, "PyObject $(pystring(o))")
end
```
with
```julia
function show(io::IO, o::PyObject)
str = pystring(o)
sep = contains(str, "\n") ? "\n" : " " # Avoid misaligning the first line for multiline prints
print(io, "PyObject$sep$str")
end
```
which gives the following print instead.
```
PyObject
┌───┐
q_0: ┤ X ├
└───┘
```

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.