-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make dict expression inference more consistent (#15174)
Fixes #12977 IMO current dict expression inference logic is quite arbitrary: we only take the non-star items to infer resulting type, then enforce it on the remaining (star) items. In this PR I simplify the logic to simply put all expressions as arguments into the same call. This has following benefits: * Makes everything more consistent/predictable. * Fixes one of top upvoted bugs * Makes dict item indexes correct (previously we reshuffled them causing wrong indexes for non-star items after star items) * No more weird wordings like `List item <n>` or `Argument <n> to "update" of "dict"` * I also fix the end position of generated expressions to show correct spans in errors The only downside is that we will see `Cannot infer type argument` error instead of `Incompatible type` more often. This is because `SupportsKeysAndGetItem` (used for star items) is invariant in key type. I think this is fine however, since: * This only affects key types, that are mixed much less often than value types (they are usually just strings), and for latter we use joins. * I added a dedicated note for this case
- Loading branch information
1 parent
fea5c93
commit 541639e
Showing
7 changed files
with
89 additions
and
65 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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