Skip to content

Commit

Permalink
chore(dev-tools): add some more type hints (#10427)
Browse files Browse the repository at this point in the history
  • Loading branch information
NickCrews authored Nov 10, 2024
1 parent f4991ff commit 9245da7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions ibis/expr/types/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def __reduce__(self):
def __hash__(self):
return hash((self.__class__, self._arg))

def equals(self, other):
def equals(self, other) -> bool:
"""Return whether this expression is _structurally_ equivalent to `other`.
If you want to produce an equality expression, use `==` syntax.
Expand Down Expand Up @@ -375,7 +375,7 @@ def _find_backend(self, *, use_default: bool = False) -> BaseBackend:

return backends[0]

def get_backend(self):
def get_backend(self) -> BaseBackend:
"""Get the current Ibis backend of the expression.
Returns
Expand Down
2 changes: 1 addition & 1 deletion ibis/expr/types/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1561,7 +1561,7 @@ def _bind_to_parent_table(self, value) -> Value | None:
return literal(value)
return value

def __deferred_repr__(self):
def __deferred_repr__(self) -> str:
return f"<column[{self.type()}]>"

def approx_nunique(self, where: ir.BooleanValue | None = None) -> ir.IntegerScalar:
Expand Down
18 changes: 12 additions & 6 deletions ibis/expr/types/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from collections import deque
from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
from keyword import iskeyword
from typing import TYPE_CHECKING, Any, Literal
from typing import TYPE_CHECKING, Any, Literal, NoReturn, overload

import toolz
from public import public
Expand Down Expand Up @@ -286,7 +286,7 @@ def bind(self, *args: Any, **kwargs: Any) -> tuple[Value, ...]:
result.append(value)
return tuple(result)

def as_scalar(self) -> ir.ScalarExpr:
def as_scalar(self) -> ir.Scalar:
"""Inform ibis that the table expression should be treated as a scalar.
Note that the table must have exactly one column and one row for this to
Expand Down Expand Up @@ -560,6 +560,12 @@ def preview(
console_width=console_width,
)

@overload
def __getitem__(self, what: str | int) -> ir.Column: ...

@overload
def __getitem__(self, what: slice | Sequence[str | int]) -> Table: ...

def __getitem__(self, what: str | int | slice | Sequence[str | int]):
"""Select one or more columns or rows from a table expression.
Expand Down Expand Up @@ -697,7 +703,7 @@ def __getitem__(self, what: str | int | slice | Sequence[str | int]):
else:
return self.select(values)

def __len__(self):
def __len__(self) -> NoReturn:
raise com.ExpressionError("Use .count() instead")

def __getattr__(self, key: str) -> ir.Column:
Expand Down Expand Up @@ -4779,13 +4785,13 @@ def unnest(

@public
class CachedTable(Table):
def __exit__(self, *_):
def __exit__(self, *_) -> None:
self.release()

def __enter__(self):
def __enter__(self) -> CachedTable:
return self

def release(self):
def release(self) -> None:
"""Release the underlying expression from the cache."""
current_backend = self._find_backend(use_default=True)
return current_backend._finalize_cached_table(self.op().name)
Expand Down

0 comments on commit 9245da7

Please sign in to comment.