add dynamic evaluation of __all__ as a list comprehension #1877
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds fairly minimal support for dynamically evaluated
__all__
values, specifically when using list comprehensions.Example:
Justification
I am working on a project that pylance takes forever to update the type annotations, and frequently stops giving me code suggestions when working with sympy. I suspect its because it has a lot of
*
imports. However, it's not entirely feasible for me to manually add__all__
to all the modules.This will allow me to keep using
*
imports, but also limit the import tree, without having to waste time updating__all__
manually, or setting up some tool to do it automatically. This approach also does not allow arbirary code execution, since the evaluation of the list comprehension is done analytically, not by actually executing any python code.Why draft?
I'm looking for feedback before I do any more work on this. Do I have the right approach here? Does pyright already have an expression evaluator or something similar that I should be using instead? Should I move
createFilterFunction
out of the binder?What should I do for tests? I added a couple, but I had to export a field that was private.
Additional Context
Fixes:
from pygments.lexers import DiffLexer
unknown pylance-release#1032Related: