Skip to content

Commit

Permalink
compiler: Fix exception messages when operator cannot be found
Browse files Browse the repository at this point in the history
  • Loading branch information
dnicolodi committed Jun 30, 2024
1 parent 683132d commit 73d9a43
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions beanquery/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def _unaryop(self, node: ast.UnaryOp):
function = types.function_lookup(OPERATORS, type(node), [operand])
if function is None:
raise CompilationError(
f'operator "{type(node).__name__.lower()}({operand.dtype.__name__})" not supported', node)
f'operator "{type(node).__name__.lower()}({types.name(operand.dtype)})" not supported', node)
function = function(operand)
# Constants folding.
if isinstance(operand, EvalConstant):
Expand Down Expand Up @@ -593,7 +593,7 @@ def _binaryop(self, node: ast.BinaryOp):

raise CompilationError(
f'operator "{type(node).__name__.lower()}('
f'{left.dtype.__name__}, {right.dtype.__name__})" not supported', node)
f'{types.name(left.dtype)}, {types.name(right.dtype)})" not supported', node)

@_compile.register
def _constant(self, node: ast.Constant):
Expand Down
2 changes: 2 additions & 0 deletions beanquery/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,6 @@ def function_lookup(functions, name, operands):


def name(datatype):
if datatype is NoneType:
return 'NULL'
return getattr(datatype, 'name', datatype.__name__.lower())

0 comments on commit 73d9a43

Please sign in to comment.