Skip to content

Commit

Permalink
fix(deferred): don't pass expression in fstringified error message
Browse files Browse the repository at this point in the history
This is a weird one, BUT:
- There is (at least) one case where, when trying to resolve a deferred
value, we end up at the `CoercionError` exception with a non-deferred
expression.

When `ibis.options.interactive = True`, we then attempt to render that
expression using `rich` because that's what f-strings do.

Even though in the calling code, which here is in `CoercedTo.match`, we
catch the `CoercionError`, the `CoercionError` never gets thrown because
we've instead errored out trying to render an f-string that will never
be seen.

If, instead of rendering the expression, we instead mention the
expression type, that prevents the short-circuit.
  • Loading branch information
gforsyth authored and cpcloud committed Dec 5, 2023
1 parent 6bc9e15 commit 724859d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ibis/common/deferred.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ def __coerce__(cls, value):
elif isinstance(value, Deferred):
return value._resolver
else:
raise CoercionError(f"Cannot coerce {value!r} to {cls.__name__!r}")
raise CoercionError(
f"Cannot coerce {type(value).__name__!r} to {cls.__name__!r}"
)


class Deferred(Slotted, Immutable, Final):
Expand Down

0 comments on commit 724859d

Please sign in to comment.