chore(stubgen): __all__ correctness#2813
Open
Rayahhhmed wants to merge 3 commits intofacebook:mainfrom
Open
Conversation
|
@yangdanny97 has imported this pull request. If you are a Meta employee, you can view this in D96861208. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
7676cf8 to
044f43a
Compare
Contributor
|
@migeed-z why is mypy primer showing a huge delta here? this PR should be a no-op |
01cad74 to
9b97de8
Compare
Contributor
The fix landed. It's looking normal again on new PRs. |
9b97de8 to
376b031
Compare
Author
|
Rebased on main again! Thanks @migeed-z :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Context
When a Python module defines
__all__, it explicitly declares its public API. Before this change, pyrefly stubgen ignored__all__entirely and relied solely on naming conventions (skip _ prefixed names which is correct).However, this meant that internal helpers not in
__all__leaked into the generated stub, and private names explicitly listed in__all__could be incorrectly filtered out.For example, given:
Before:
unlisted_funcappeared in the stub (wrong),_explicitly_exportedwas excluded (wrong).After: Only
public_funcandPublicClassappear and this is exactly what__all__specifies.Approach
__all__, since they may be needed for type resolution in the stub.should_include_name(), which short-circuits at module level: if__all__is present, only listed names pass. Inside classes,__all__is irrelevant and the existing convention logic applies unchanged.__all__is absent, unresolvable, or contains cross-module re-exports.Test plan
__all__python3 test.py --no-test --no-conformancepasses