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

__all__ not being respected from an import * #619

Closed
brettcannon opened this issue Feb 15, 2019 · 3 comments · Fixed by #863
Closed

__all__ not being respected from an import * #619

brettcannon opened this issue Feb 15, 2019 · 3 comments · Fixed by #863
Assignees
Milestone

Comments

@brettcannon
Copy link
Member

microsoft/vscode-python#494

# A.py
import B
B. # intellisense shows `foo` and `bar`, but should only show `foo`.

# B.py
from C import *

# C.py
__all__ = ['foo']
foo = 42
bar = 24
@jakebailey
Copy link
Member

Works in the new language server.

image

We have basic __all__ support, though not for more complicated expressions (like those which combine multiple modules' __all__s into a single list).

@jakebailey
Copy link
Member

An unfortunate side effect of handling this but only partially means that we may under complete in some situations (especially projects like Django which do lots of fun stuff). I've opened #620 to track improving the support.

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
Copy link
Member

Repoening, the code which filters __all__ has been temporarily removed as commonly used libraries are using it in ways we can't handle yet.

@jakebailey jakebailey reopened this Mar 6, 2019
@jakebailey jakebailey self-assigned this Mar 20, 2019
@MikhailArkhipov MikhailArkhipov added this to the March 2019.2 milestone Mar 26, 2019
jakebailey added a commit that referenced this issue Apr 2, 2019
Fixes #620.
Fixes #619.

This adds support for concatenating lists using `+`, doing `+=` on `__all__`, and calling `append` and `extend` on `__all__`. If something goes wrong (an unsupported operation on `__all__` or some unsupported value), then the old behavior continues to be used. I don't track uses of `__all__` indirectly (i.e. passing `__all__` to something that modifies it), only direct actions. If `__all__` is in a more complicated lvar (like `__all__, foo = ...`), then it is ignored. This can be improved later on when we fix up our multiple assignment issues.

This works well for Django models (see #620), but `numpy`'s import cycles prevent this from having an effect, so the old behavior will be used.

~Tests are WIP.~ I'll need to rebase/merge master when the refs per gets merged.
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.
jakebailey added a commit to jakebailey/python-language-server that referenced this issue Nov 1, 2019
Fixes microsoft#620.
Fixes microsoft#619.

This adds support for concatenating lists using `+`, doing `+=` on `__all__`, and calling `append` and `extend` on `__all__`. If something goes wrong (an unsupported operation on `__all__` or some unsupported value), then the old behavior continues to be used. I don't track uses of `__all__` indirectly (i.e. passing `__all__` to something that modifies it), only direct actions. If `__all__` is in a more complicated lvar (like `__all__, foo = ...`), then it is ignored. This can be improved later on when we fix up our multiple assignment issues.

This works well for Django models (see microsoft#620), but `numpy`'s import cycles prevent this from having an effect, so the old behavior will be used.

~Tests are WIP.~ I'll need to rebase/merge master when the refs per gets merged.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants