Misalignment of first line in multiline show of PyObject
- 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.