Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jedi.Script.Complete doesn't return expected result when package has only __init__.pyc and __init__.pyi #1949

Open
crow3399 opened this issue Jul 20, 2023 · 8 comments

Comments

@crow3399
Copy link

Hi, I'm using vscode with jedi and developing a python package, there are init.pyc and init.pyi in the package' root directory. When I run:

jedi.Script('from myPackage.').complete(line = 1, column = 15)

the result is empty list. After I delete the init.pyc in root directory, the function will return expected result. But when I click 'go to definition' on myPackage, the result is 'No definition found'.

What's more, there init.pyc and init.pyi in myPackage\subFolder, When I run:

jedi.Script('from myPackage.subFolder import .').complete(line = 1, column = 32)

the result does not include the members of all, which is defined in init.pyi. If I add init.py in subFolder, the function will return expected result.

I'm not sure if these are bug or I should restructure my package.
version of jedi is 0.18.2.
Thank you.

@davidhalter
Copy link
Owner

Sorry, but without a list of files to reproduce this issue, I have no idea what your problem is.

There is an almost 0 percent change that this simple use case doesn't work like it should, because cases like these have been tested very well within Jedi. So I'm a bit surprised that you have problems here.

@crow3399
Copy link
Author

crow3399 commented Jul 21, 2023

How about creating a folder in site-package like:

mypackage
├── __init__.pyc
├── __init__.pyi
└── subFolder
├──── __init__.pyi

all files are renamed from empty txt.
content in subFolder\ __init__.pyi:

from .f1 import mem1
from .f2 import mem2

__all__ = [
'mem1',
'mem2'
]

@davidhalter
Copy link
Owner

As long as you do not give me a zip file with an executable file that reproduces your issue, I cannot do anything for you.

@crow3399
Copy link
Author

jediissue.zip
sorry, I should upload early. please extract the file ,then move mypackage to site-packages.

@crow3399
Copy link
Author

crow3399 commented Jul 25, 2023

Is this zip enough? Thanks.

@davidhalter
Copy link
Owner

Thanks a lot for the clean reproduction folder.

It indeed looks like a bug. Thanks for bringing this up! I'm not sure if this should be a namespace package or not. Regardless completions should always work in this case. Oddly enough, it's weird that after removing the mypackage/__init__.pyc everything works like expected, even in the mypackage/subfolder, where's the same structure and the same __init__.pyc, that could be annoying.

Please note that this is a bit of an obscure issue and does not have the highest priority. Feel free to try to fix it. I'm happy to help you a bit if you want to.

@crow3399
Copy link
Author

@davidhalter Hi, I want to know why sub_modules_dict is not implemented for compiled modules, I copied code of sub_modules_dict to CompiledModule, then Script.Complete return expected value. Thanks!
image

@davidhalter
Copy link
Owner

davidhalter commented Aug 18, 2023

That's actually fine probably. I feel like the real question is: Why is __init__.pyc preferred over __init__.pyi.

I'm not sure I want sub_modules_dict for compiled modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants