Skip to content

feat(typing): make common Expr.__dunder__ methods more type specific#11966

Open
NickCrews wants to merge 1 commit intoibis-project:mainfrom
NickCrews:typing-inferrable-to
Open

feat(typing): make common Expr.__dunder__ methods more type specific#11966
NickCrews wants to merge 1 commit intoibis-project:mainfrom
NickCrews:typing-inferrable-to

Conversation

@NickCrews
Copy link
Copy Markdown
Contributor

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.

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.
@github-actions github-actions bot added the datatypes Issues relating to ibis's datatypes (under `ibis.expr.datatypes`) label Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

datatypes Issues relating to ibis's datatypes (under `ibis.expr.datatypes`)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant