Refuse variable inlining across lazy type alias boundaries - #890
Open
yangfan-yf-yf wants to merge 1 commit into
Open
yangfan-yf-yf wants to merge 1 commit into
yangfan-yf-yf wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #890 +/- ##
==========================================
+ Coverage 95.34% 95.36% +0.02%
==========================================
Files 134 135 +1
Lines 26819 26942 +123
==========================================
+ Hits 25570 25693 +123
Misses 1249 1249 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Inlining a variable used by a PEP 695 type alias can change when its initializer runs and which binding the alias resolves. For example, inlining
targetbelow changes the output fromTruetoFalse:I added a preflight check that raises
RefactoringErrorwhen a variable reference occurs within a type alias. This preserves the source instead of moving the initializer into a lazy context. A partial inline of an eager reference remains available withonly_current=True, remove=False; removing a binding still used by a type alias is refused.The regression tests execute source before and after the operation, covering side effects and late name binding as well as cross-module references, type parameter bounds, multiline and Unicode aliases, partial inlining, and unrelated/shadowed-name controls. On the unmodified base, 13 of the 17 new cases fail; all 17 pass with this change.
This follows the runtime-semantics testing direction in Discussion #875. It addresses ordinary variables referenced inside type aliases, separately from #874's handling of selecting a type-alias definition for inlining. Deferred function/variable annotations and type parameters outside type aliases are outside this change.
Validation:
Checklist: