jedi icon indicating copy to clipboard operation
jedi copied to clipboard

TAB completion does not work for packages that use native namespaces.

Open ghuls opened this issue 10 months ago • 0 comments

TAB completion does not work for packages that use native namespaces (where the parent dir does not have _init__.py

Originally reported at https://github.com/ipython/ipython/issues/14806 and https://github.com/kylebarron/arro3/issues/290

TAB completion does not work for packages that use native namespaces: https://packaging.python.org/en/latest/guides/packaging-namespace-packages/#native-namespace-packages

Original bug report: https://github.com/kylebarron/arro3/issues/290

Currently when installing the 3 arrow3 packages, the structure looks like this:

$ ls /lib/python3.11/site-packages/arro3/
compute core  io     

When importing the modules in ipython, tab completion is not working (to find the functions in each module

In [4]: import arro3.io

In [5]: import arro3.core

In [6]: import arro3.compute

In [7]: arro3.io.<TAB> ==> no list of functions.

When importing them with an alias, tab completion works:

In [1]: import arro3.io as arro3_io

In [2]: import arro3.compute as arro3_compute

In [3]: import arro3.core as arro3_core

In [4]: arro3_io.<TAB>
 infer_csv_schema()   read_csv()           read_ipc_stream()    read_parquet()       store                write_ipc()          write_json()         write_parquet()     
 infer_json_schema()  read_ipc()           read_json()          read_parquet_async() write_csv()          write_ipc_stream()   write_ndjson()                           

When adding just an empty _init__.py at /lib/python3.11/site-packages/arro3/__init__.py, tab completion works:

In [1]: import arro3.io as arro3_io

In [2]: import arro3.compute as arro3_compute

In [3]: import arro3.core as arro3_core

In [4]: arro3.io.<TAB>
 infer_csv_schema()   read_csv()           read_ipc_stream()    read_parquet()       store                write_ipc()          write_json()         write_parquet()     
 infer_json_schema()  read_ipc()           read_json()          read_parquet_async() write_csv()          write_ipc_stream()   write_ndjson()           

Reply:

When adding just an empty init_.py at /lib/python3.11/site-packages/arro3/init.py, tab completion works:

In theory, that is supposed to break namespace packaging: https://packaging.python.org/en/latest/guides/packaging-namespace-packages/#native-namespace-packages

All that is required to create a native namespace package is that you just omit init.py from the namespace package directory

In [37]: IPython.__version__
Out[37]: '8.32.0'

In [38]: jedi.__version__
Out[38]: '0.19.2'

ghuls avatar Feb 28 '25 10:02 ghuls