def nullify_expr_field(self, schema, context, field, op): from edb.edgeql.compiler import astutils as qlastutils if field.name == 'expr': base = self.get_attribute_value('bases').first(schema) if base.is_object_type(): base_name = base.get_name(schema) ql = qlast.SelectQuery( result=qlast.Path(steps=[ qlast.ObjectRef( name=base_name.name, module=base_name.module, ), ], ), where=qlast.BooleanConstant(value='false'), ) else: ql = qlast.TypeCast( expr=qlast.Set(), type=qlastutils.type_to_ql_typeref(base, schema=schema), ) op.new_value = s_expr.Expression.compiled( s_expr.Expression.from_ast(ql, schema=schema, modaliases=context.modaliases), schema=schema, ) return True else: super().nullify_expr_field(schema, context, field, op)
def const_ast_from_python(val: Any) -> qlast.BaseConstant: if isinstance(val, str): return qlast.StringConstant.from_python(val) elif isinstance(val, bool): return qlast.BooleanConstant(value='true' if val else 'false') elif isinstance(val, int): if MIN_INT64 <= val <= MAX_INT64: return qlast.IntegerConstant(value=str(val)) else: raise ValueError(f'int64 value out of range: {val}') elif isinstance(val, decimal.Decimal): return qlast.DecimalConstant(value=f'{val}n') elif isinstance(val, float): return qlast.FloatConstant(value=str(val)) elif isinstance(val, bytes): return qlast.BytesConstant.from_python(value=val) else: raise ValueError(f'unexpected constant type: {type(val)!r}')
def reduce_FALSE(self, *kids): self.val = qlast.BooleanConstant(value='false')
def reduce_TRUE(self, *kids): self.val = qlast.BooleanConstant(value='true')
def visit_BooleanValue(self, node): value = 'true' if node.value else 'false' return qlast.BooleanConstant(value=value)
def visit_BooleanConstant(self, node): return qlast.BooleanConstant(value=node.value)