davidhalter / jedi-vim

Using the jedi autocompletion library for VIM.
MIT License
5.27k stars 370 forks source link

Autocomplete from imports using SourceFileLoader #1065

Closed mdforti closed 2 years ago

mdforti commented 2 years ago

Issue

Steps to reproduce

editing python script import module and possibly classes using importlib.machinery.SourceFileLoader instead of normal import start new object try to autocomplete property or method from new instance ompni completion wont find pattern.

I don't know if this is a bug or a missing feature, but it would be great to have it working at some point.

Thank you all for the help and the great tool.

davidhalter commented 2 years ago

This is not enough to reproduce your issue. You probably need to send your source file.

mdforti commented 2 years ago

exaple.py:

class greeter:
    def __init__(self):
        self.greet_phrase = "Hello World"
        pass

    def greet(self):
        print(self.greet_phrase)

noautocomplete.py

from importlib.machinery import SourceFileLoader

greeter = SourceFileLoader('greeter', 'example.py').load_module().greeter

G=greeter()

G.greet()

yesautocomplete.py:

from example import greeter

G = greeter()

G.greet()

a little context: I use SourceFileLoader to import modules that I am developing or changing or that are not yet installed in environment.

davidhalter commented 2 years ago

SourceFileLoader and other dynamic things like changing a module's dict or using setattr are not supported. Just set the sys path properly.

mdforti commented 2 years ago

ok, thats clear now. Thank you !