-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Computed "__all__" value results in nothing being exported. #12582
Comments
Maintainers of the various Python type checkers had a discussion about this topic on the typing-sig email list a couple of years ago. In particular, we discussed I analyzed a bunch of libraries and, based on this analysis, recommended a list of forms that static analysis tools should support. This list is documented here. I'll also paste the list here for completeness:
Pyright supports this list of expression forms (and no others). I'll note that the list does not include |
+1 to everything Eric said. I think mypy currently supports most things on Eric's list; I believe the forms mypy does not yet support are the ones involving |
Is there any plan to add support for the forms involving |
@AustinScola Mind creating a separate issue for this? Otherwise this legitimate feature request might be lost in the shuffle. And then we should either:
|
See python#12582. pyright supports this pattern as well.
See #12582. pyright supports this pattern as well.
Bug Report
I have two modules:
To Reproduce
mypy .
Expected Behavior
No errors
Actual Behavior
Note:
If you make the change:
Then the output is:
In method
semanal.SemanticAnalyzer.process__all__(self, s: AssignmentStmt)
, it only recognizess.rvalue
as being either aTupleExpr
or aListExpr
.In this particular case, it is a
CallExpr
node. The callee is aMemberExpr
with aStrExpr
as the object andsplit
as the member name.Other cases that mypy should recognize would include redefining
__all__
, as in__all__.append("Baz")
.I realize that by design, mypy never executes any user code, so it would be inappropriate to compile and execute the rvalue expression (i.e. there could be something dangerous). However, I think that by analyzing the syntax tree, it can be determined that it has constant value, and what that value is.
I wonder when it is always safe to compile and execute an arbitrary expression. Can you construct some sort of sandbox which is isolated from the current running environment?
At any rate, I'd like to see a robust ability in mypy to recognize expressions which have a constant value.
Your Environment
The text was updated successfully, but these errors were encountered: