Better names of and more compatibility between ad hoc intersections of instances #18506
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.
While working on #18433, we encountered this bug.. @ilevkivskyi identified the underlying problem, and we decided to try to reuse previously created ad hoc intersections of instances instead of always creating new ones.
While working on this PR, I realised that reusing intersections requires more complete names. Currently, module and type variable specifications are not included, which could result in mistakes when using these names as identifiers.
So, I switched to more complete names. Now, for example,
<subclass of "A" and "A">
becomes<subclass of "mod1.A[builtins.int]" and "mod2.A">
. Hence, I had to adjust many existing test cases wherereveal_type
is used.testReuseIntersectionForRepeatedIsinstanceCalls
confirms that the mentioned bug is fixed.testIsInstanceAdHocIntersectionIncrementalNestedClass
andtestIsInstanceAdHocIntersectionIncrementalUnions
are in a separate commit. I think they are not really necessary, so we might prefer to remove them. I added them originally because I had to adjustlookup_fully_qualified
a little. The change is very simple, but I could not create a test case where it is not sufficient.