Skip to content
This repository has been archived by the owner on Apr 14, 2022. It is now read-only.

Missing numpy and tensorflow completion, members not showing up #642

Closed
jakebailey opened this issue Feb 20, 2019 · 7 comments
Closed

Missing numpy and tensorflow completion, members not showing up #642

jakebailey opened this issue Feb 20, 2019 · 7 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@jakebailey
Copy link
Member

numpy and tensorflow.nn are missing completion.

import numpy as np
np.

Nothing shows up after np. except some oddball stuff.

Doing this:

import tensorflow
tensorflow.nn

nn has no completion, and tensorflow.nn itself doesn't say that nn exists at all.

@MikhailArkhipov
Copy link

This is about submodules in folders you are working on

@MikhailArkhipov
Copy link

Related: #490

from setuptools. # misses `archive*`

image

@jakebailey
Copy link
Member Author

So in looking at #690, I realized that I hadn't checked __all__ for numpy, and behold:

https://github.com/numpy/numpy/blob/15b092f5541e80d7c3d0108957406c6f8686aba0/numpy/__init__.py#L169

    __all__.extend(['__version__', 'show_config'])
    __all__.extend(core.__all__)
    __all__.extend(_mat.__all__)
    __all__.extend(lib.__all__)
    __all__.extend(['linalg', 'fft', 'random', 'ctypeslib', 'ma'])

Which explains why we aren't getting numpy completion anymore; we have the __all__ filtering.

@jakebailey
Copy link
Member Author

jakebailey commented Mar 5, 2019

Commenting out all of the code in PythonModule.GetMemberNames which filters:

image

It's really slow to show up, but it's there. Maybe we need to drop the filters for now until we can better handle __all__. The old LS worked because it didn't even do anything.

@MikhailArkhipov
Copy link

If we drop all filters then all the typing and others imported will show up in the completion. But it may be smaller price to pay.

@jakebailey
Copy link
Member Author

The above is just:

            // Try __all__ since it contains exported members
            var all = Analysis.GlobalScope.Variables["__all__"];
            // if (all?.Value is IPythonCollection collection) {
            //     return collection.Contents
            //         .OfType<IPythonConstant>()
            //         .Select(c => c.GetString())
            //         .Where(s => !string.IsNullOrEmpty(s));
            // }

            // __all__ is not declared. Try filtering by origin:
            // drop imported modules and generics.
            return Analysis.GlobalScope.Variables
                .Where(v => !(v.Value?.GetPythonType() is PythonModule)
                            && !(v.Value?.GetPythonType().DeclaringModule is TypingModule && !(this is TypingModule)))
                // .Where(v => v.Value?.MemberType != PythonMemberType.Generic
                //             && !(v.Value?.GetPythonType() is PythonModule)
                //             && !(v.Value?.GetPythonType().DeclaringModule is TypingModule && !(this is TypingModule)))
                .Select(v => v.Name);

So theoretically I'm not leaking typing or modules out.

@MikhailArkhipov
Copy link

OK, sure

jakebailey added a commit that referenced this issue Mar 6, 2019
Fixes #642.
Reopens #619.
Related #620.

This unfilters exported variables except for things which are directly from typing or are imported modules, though even that may be too strong. The old LS didn't look at __all__ whatsoever, so maybe all of these should be allowed to come through; you tell me.
@jakebailey jakebailey self-assigned this Mar 6, 2019
jakebailey added a commit to jakebailey/python-language-server that referenced this issue Nov 1, 2019
Fixes microsoft#642.
Reopens microsoft#619.
Related microsoft#620.

This unfilters exported variables except for things which are directly from typing or are imported modules, though even that may be too strong. The old LS didn't look at __all__ whatsoever, so maybe all of these should be allowed to come through; you tell me.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants