PyCall.jl icon indicating copy to clipboard operation
PyCall.jl copied to clipboard

Nested autocompletion

Open carstenbauer opened this issue 7 years ago • 4 comments

Autocompletion (tab) does work here

@pyimport numpy as np
np.linalg.<tab>

but doesn't here

np = pyimport("numpy")
np.linalg.<tab>

carstenbauer avatar Mar 18 '19 14:03 carstenbauer

This might be a REPL limitation. It would need to evaluate numpy.linalg in order to call propertynames for tab completion, but I don’t think it will evaluate expressions bigger than a single symbol unless they are struct fields.

If you assign linalg to a variable it should work.

stevengj avatar Mar 18 '19 15:03 stevengj

That's a bummer. In particular because we deprecated @pyimport in favor of pyimport,

julia> @pyimport numpy as np
┌ Warning: `@pyimport foo` is deprecated in favor of `foo = pyimport("foo")`.
│   caller = _pywrap_pyimport(::PyObject) at PyCall.jl:400
└ @ PyCall C:\Users\carsten\.julia\packages\PyCall\RQjD7\src\PyCall.jl:400

(I can confirm that it works when assigning np.linalg to a variable.)

carstenbauer avatar Mar 18 '19 15:03 carstenbauer

In particular, we reach this line of REPLCompletions: numpy.linalg is an "advanced expression" that it doesn't want to evaluate.

This is reasonable — I don't think anyone wants REPL tab-completion to just execute arbitrary code, which is what would happen if it automatically called getproperty.

Sorry, @pyimport is not coming back. It's just not a good long-term approach to pre-emptively evaluate every symbol in a Python module and stick them all into a Julia module, and it doesn't work for doubly nested modules or any other Python object. @pyimport was a hack to temporarily work around the lack of dot overloading (which lasted a lot longer than I hoped).

The only way to improve this going forward would be to design an API for the REPL stdlib that tells it when we want it to evaluate getproperty dot expressions during tab completion.

stevengj avatar Mar 18 '19 16:03 stevengj

Does https://github.com/JuliaLang/julia/pull/49206 have any impact on this?

antoine-levitt avatar May 05 '23 08:05 antoine-levitt