JuliaPy / JuliaPy/PyCall.jl

Misalignment of first line in multiline show of PyObject

Aperta Adatta ai principianti
#888 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Julia
Stelle
1.5k
Fork
186
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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 ├
└───┘
```

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Start at the show(io::IO, o::PyObject) implementation and reproduce the issue with a PyObject whose pystring result contains newlines, using the provided qiskit example. Verify that single-line output keeps its spacing while multiline output places PyObject on its own line and no longer misaligns the first row.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
julia, python
Ambito
tooling
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
68/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.