[ty] Experiment with canonical empty generic contexts - #29127
Draft
dhruvmanila wants to merge 1 commit into
Draft
dhruvmanila wants to merge 1 commit into
dhruvmanila wants to merge 1 commit into
Conversation
A nongeneric signature can carry either no generic context or an empty one, for example after binding the only Self type variable. These representations compare differently even though they describe the same signature, creating redundant alternatives during constraint solving. Represent GenericContext as None or Some(GenericContextInner), with the construction APIs returning None for empty collections. Keep Program and the ordered variables directly in the interned inner struct, and update callers to handle the empty variant without retaining a separate Option wrapper. Preserve the distinction between absent and incomplete PEP 695 syntax using the existing class syntax flag. Adapt existing test helpers to the new API.
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 98.24%. The percentage of expected errors that received a diagnostic held steady at 98.24%. The number of fully passing files held steady at 134/146. |
Memory usage reportSummary
Significant changesClick to expand detailed breakdownflake8
trio
sphinx
prefect
|
|
| Project | Old Time | New Time | Change |
|---|---|---|---|
django-modern-rest |
0.07s | 0.02s | -65% |
This branch was successfully 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.
Option<GenericContext>permits two equivalent empty representations:NoneandSome(empty). Binding a callback method's soleSelfvariable can produce the latter while an equivalent direct callable carries the former, allowing equivalent constraint alternatives to remain distinct.This experiments with
GenericContext::{None, Some(GenericContextInner)}, followingTypeVarSet. Normal construction APIs canonicalize empty collections toNone; the interned inner value holds the program and ordered variables directly. Callers operate onGenericContextwithout an additionalOption.The purpose is feedback on this representation and whether it overlaps with planned generic-context work. This is independent of #28828, which uses a smaller normalization fix.