feat(typing): make common Expr.__dunder__ methods more type specific#11966
Open
NickCrews wants to merge 1 commit intoibis-project:mainfrom
Open
feat(typing): make common Expr.__dunder__ methods more type specific#11966NickCrews wants to merge 1 commit intoibis-project:mainfrom
__dunder__ methods more type specific#11966NickCrews wants to merge 1 commit intoibis-project:mainfrom
Conversation
Before, doing `IntegerValue.__le__()` would fall back to the base `Value.__le__()` method, which was typed as `__le__(self, other: Value) -> ir.BooleanValue`. This made eg `my_int_value <= 5` not pass the type checker. In this PR: - I added comprehesive type aliases to describe the sorts of things that can be converted to Literals - ibis.literal() now accepts `Inferrable` type, not `Any`. It would be possible to now add a bunch of @Overloads so the return type was more speicifc, but I punted on that - now the `__dunder__` methods of the common ibis Value subclasses, such as StringValue, are typed quite precisely. The less common ones, such as `PointValue`, are not just because I don't want to spend the time in this PR. IF this lands then we can follow up. - now the `__dunder__` methods of Value are typed much more loosely, so that for the non-override subclasses such as PointValue, you don't get type errors. I think in general we should strive to throw fewer type errors at our users when possible.
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.
Before, doing
IntegerValue.__le__()would fall back to the baseValue.__le__()method, which was typed as__le__(self, other: Value) -> ir.BooleanValue. This made egmy_int_value <= 5not pass the type checker.In this PR:
Inferrabletype, notAny. It would be possible to now add a bunch of @Overloads so the return type was more speicifc, but I punted on that__dunder__methods of the common ibis Value subclasses, such as StringValue, are typed quite precisely. The less common ones, such asPointValue, are not just because I don't want to spend the time in this PR. IF this lands then we can follow up.__dunder__methods of Value are typed much more loosely, so that for the non-override subclasses such as PointValue, you don't get type errors. I think in general we should strive to throw fewer type errors at our users when possible.