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

Add completion on a variable if it matches a module name #1042

Closed
ColinKennedy opened this issue Feb 12, 2018 · 4 comments
Closed

Add completion on a variable if it matches a module name #1042

ColinKennedy opened this issue Feb 12, 2018 · 4 comments
Labels

Comments

@ColinKennedy
Copy link

ColinKennedy commented Feb 12, 2018

I have a scenario where I'd like to get completion for some unknown object. The idea is that, though the object is completely unknown, the variable name of that object also matches the name of an importable module. The completion options for that object will just be the same as if it were an imported module.

Minimal Example:

import imp
textwrap = imp.load_source('textwrap', '/usr/lib64/python2.7/textwrap.py')
textwrap.[cursor_position]
# Expected completion options: ['TextWrapper', 'dedent', 'fill', 're', 'string', 'wrap', '__all__', '__revision__', '_leading_whitespace_re', '_unicode', '_whitespace', '_whitespace_only_re']

I must stress though that I wouldn't want this to be the default behavior, just something for a couple select module/variable names that I knew in advance that I wanted this for.

Full Context:

I use rpyc to communicate between two Python interpreter sessions. On the client side, I have to assign the connection as a variable and the variable's name shadows the import. Jedi tries to complete for the nuke variable which has no completions and not the nuke module, which has all the completions.

import nuke
nuke, connection = import_remote_server()
nuke.[cursor_position]  # No completion options

The function import_remote_server() has to be after the import because the object that it returns is basically the namespace needed to communicate with the server. But adding it after the import shadows the module name and all completion is lost, because of that. I wrote a search/replace script that is something like a "best of both worlds" scenario but was also wondering if there was a simpler way to achieve this.

I use Jedi with the latest YouCompleteMe, Vim 8.0, on CentOS 7. Any help would be greatly appreciated

@ColinKennedy ColinKennedy changed the title Fake object completion if it matches a module name Add completion on a variable if it matches a module name Feb 12, 2018
@davidhalter
Copy link
Owner

Why don't you use type annotations?

@ColinKennedy
Copy link
Author

ColinKennedy commented Feb 12, 2018

I don't have control over the module I'm importing - it's 3rd party - and it's also based on Python 2, unless you meant something else? I'm not familiar with type annotations enough to know what you're suggesting

@davidhalter
Copy link
Owner

Well I guess I'm starting to understand.

I'm not sure if there is a way to annotate something with a specific module. That might be problematic. You could for sure annotate some things that might help you, but probably not everything.

I'm keeping it open, but don't expect much progress in the next few months or even years. IMO this is something that the typing module has to solve.

@davidhalter
Copy link
Owner

I've decided that I won't further pursue this. To solve your issue in the future, please follow #626.

Once you can use Jedi plugins, you can write your own and solve your problems.

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

No branches or pull requests

2 participants