Skip to content

Jedi only recognizes first of intersecting implicit namespace packages on PYTHONPATH #1759

@andrew-christianson

Description

@andrew-christianson

If multiple implicit namespaces packages share a common path, but are located in two different directories on disk, recent versions of Jedi return completions for only the first package found in in the search path. For example, given two PEP420 packages with a common prefix, but different locations like:

pkg1
└── aa
    └── bb
        └── cc
            └── one.py
pkg2
└── aa
    └── bb
        └── dd
            └── two.py

then completions are only produced for the first package found, Goto only works for that package, etc e.g.

$ PYTHONPATH=pkg1:pkg2 ./venv/bin/python -c 'import jedi;print(jedi.Script("import aa.bb.").complete())'
[<Completion: cc>]
$ PYTHONPATH=pkg1:pkg2 ./venv/bin/python -c 'import jedi;print(jedi.Script("from aa.bb.dd.two import b;b.").complete())'
[]

While the example is contrived, this situation comes up in real usage when multiple PEP420 packages are installed as editable.

This appears to mirror same issue for old-style namespace packages (#1105) - hopefully the fix is as simple?

A complete reproducible example:

mkdir -p pkg1/aa/bb/cc
mkdir -p pkg2/aa/bb/dd

echo 'a=1' > pkg1/aa/bb/cc/one.py
echo 'b=2' > pkg2/aa/bb/dd/two.py

python3 -m venv venv 
./venv/bin/python -m pip install jedi

$ PYTHONPATH=pkg1:pkg2 ./venv/bin/python -c 'import jedi;print(jedi.Script("import aa.bb.").complete())'
[<Completion: cc>]
$ PYTHONPATH=pkg2:pkg1 ./venv/bin/python -c 'import jedi;print(jedi.Script("import aa.bb.").complete())'
[<Completion: dd>]
$ PYTHONPATH=pkg1:pkg2 ./venv/bin/python -c 'import jedi;print(jedi.Script("from aa.bb.dd.two import b;b.").complete())'
[]
$ PYTHONPATH=pkg2:pkg1 ./venv/bin/python -c 'import jedi;print(jedi.Script("from aa.bb.dd.two import b;b.").complete())'
[<Completion: as_integer_ratio>, <...]

Versions:
MacOS 11.2.3
Python 3.9.2
Jedi 0.18.0, current master

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions