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

Not showing preview for python classes imported in __init__.py #3372

Closed
ApolloBian opened this issue Apr 20, 2019 · 2 comments
Closed

Not showing preview for python classes imported in __init__.py #3372

ApolloBian opened this issue Apr 20, 2019 · 2 comments

Comments

@ApolloBian
Copy link

ApolloBian commented Apr 20, 2019

Issue Details

Preview shows up fine for normal python classes / functions. But if the classes are imported in __init__.py and used elsewhere, YCM will mark these classes as m instead of c and will not show completion for them.

YCM version

Latest version (9dee2b)

Steps to reproduce:

import torch.nn as nn
import torch
a = nn.Linear(...) # does't show preview
a = torch.functional.argmax(...) # preview shows fine

Also, :YcmCompleter GetDoc command works fine on nn.Linear().

A simpler reproduction which narrows things down

make a miniproject like this:

├── foo.py
└── TestClass
    ├── __init__.py
    └── TestClass.py

in TestClass.py:

#!/usr/bin/env python
class WeakModule:
    def __init__(self):
        pass

in __init__.py:

#!/usr/bin/env python
from TestClass import WeakModule

in foo.py

import TestClass
a = TestClass.WeakModule() # won't show preview
@ApolloBian ApolloBian changed the title Not showing preview for python weakref classes? Not showing preview for some python classes? Apr 20, 2019
@ApolloBian ApolloBian changed the title Not showing preview for some python classes? Not showing preview for python classes imported in __init__.py Apr 20, 2019
@micbou
Copy link
Collaborator

micbou commented Apr 20, 2019

This is a duplicate of #3291. See my comment there.

Your minimal reproducible case is a different issue. It's not valid code on Python 3 as running foo.py raises the following error:

ImportError: cannot import name 'WeakModule' from 'TestClass'

In that case, YCM returns WeakModule as a module because when a symbol is not found, Jedi (the completion engine used by YCM for Python) assumes that it's a module.

While the code is running under Python 2, Jedi still returns WeakModule as a module so you could consider this as a Jedi bug on Python 2. Feel free to report the issue on the Jedi tracker.

@ApolloBian
Copy link
Author

ApolloBian commented Apr 21, 2019

@micbou thank you for the reply. Temporarily deleting these 6 lines makes things work fine again.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants