Consider __all__.remove when determining explicit exports - #4638
Open
kavix wants to merge 1 commit into
Open
Conversation
When checking for implicit re-exports, Pyrefly previously filtered only DunderAllEntry::Name entries from explicit __all__ definitions, ignoring subsequent __all__.remove(...) mutations. As a result, symbols removed from __all__ were still treated as explicitly exported. Compute the final explicit __all__ names by replaying mutations in source order (inserting on Name, removing on Remove), and use this resulting set for explicit export queries and implicit-reexport checks.
Contributor
|
This pull request has been imported. If you are a Meta employee, you can view this in D117137289. (Because this pull request was imported automatically, there will not be any future comments.) |
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
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.
Summary
Fixes #4564.
When checking for implicit re-exports, Pyrefly previously filtered only
DunderAllEntry::Nameentries from explicit__all__definitions, ignoring subsequent__all__.remove(...)mutations. As a result, symbols removed from__all__were still treated as explicitly exported.Changes
Exports::get_explicit_dunder_all_namesto compute the final set of user-defined__all__symbols by applying mutations in source order (inserting onName, removing onRemove), consistent withget_partially_known_dunder_allandwildcard.explicit_dunder_all_names: Option<SmallSet<Name>>onExportsand updatedget_explicit_dunder_all_names_iter,is_implicit_reexport, andchanged_exports.test_implicit_reexport_removed_from_allinpyrefly/lib/test/imports.rs.Test Plan
CARGO_BUILD_JOBS=1 cargo test -p pyrefly --lib test::imports::test_implicit_reexport_removed_from_all -- --exact --nocaptureCARGO_BUILD_JOBS=1 cargo check -p pyrefly --libCARGO_BUILD_JOBS=1 cargo check -p pyrefly --testspython3 test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschema[tool.pyrefly.errors] implicit-reexport = "error"verifying that removing a name triggers the diagnostic and appending it back silences it.AI Disclosure
This PR was developed and verified with the assistance of an AI coding assistant (Google Antigravity).