1
1
import operator
2
2
3
- from .utils import safezip , listgen , find_duplicate , SafeDict , re_split
4
- from .exceptions import Signal
5
- from . import exceptions as exc
6
3
7
- from . import settings
4
+ from preql import settings
5
+ from preql .utils import safezip , listgen , find_duplicate , SafeDict , re_split
6
+
7
+ from .exceptions import Signal , InsufficientAccessLevel , ReturnSignal , pql_AttributeError
8
8
from . import pql_objects as objects
9
9
from . import pql_ast as ast
10
10
from . import sql
@@ -27,11 +27,11 @@ def cast_to_instance(state, x):
27
27
x = simplify (state , x ) # just compile Name?
28
28
inst = compile_to_inst (state , x )
29
29
# inst = evaluate(state, x)
30
- except exc . ReturnSignal :
30
+ except ReturnSignal :
31
31
raise Signal .make (T .CompileError , None , f"Bad compilation of { x } " )
32
32
33
33
if isinstance (inst , ast .ParameterizedSqlCode ):
34
- raise exc . InsufficientAccessLevel (inst )
34
+ raise InsufficientAccessLevel (inst )
35
35
36
36
if not isinstance (inst , AbsInstance ):
37
37
# TODO compile error? cast error?
@@ -175,7 +175,7 @@ def compile_to_inst(state: State, proj: ast.Projection):
175
175
176
176
for name , f in fields :
177
177
if not f .type <= T .union [T .primitive , T .struct , T .json , T .nulltype , T .unknown ]:
178
- raise exc . Signal .make (T .TypeError , proj , f"Cannot project values of type: { f .type } " )
178
+ raise Signal .make (T .TypeError , proj , f"Cannot project values of type: { f .type } " )
179
179
180
180
if isinstance (table , objects .StructInstance ):
181
181
d = {n [1 ]:c for n , c in fields } # Remove used_defined bool
@@ -414,7 +414,7 @@ def _compare(state, op, a: T.type, b: T.type):
414
414
if op == '<=' :
415
415
return call_builtin_func (state , "issubclass" , [a , b ])
416
416
if op != '=' :
417
- raise exc . Signal .make (T .NotImplementedError , op , f"Cannot compare types using: { op } " )
417
+ raise Signal .make (T .NotImplementedError , op , f"Cannot compare types using: { op } " )
418
418
return new_value_instance (a == b )
419
419
420
420
@dp_inst
@@ -536,7 +536,7 @@ def _compile_arith(state, arith, a: T.string, b: T.string):
536
536
return objects .Instance .make (code , T .bool , [a , b ])
537
537
538
538
if arith .op != '+' :
539
- raise exc . Signal .make (T .TypeError , arith .op , f"Operator '{ arith .op } ' not supported for strings." )
539
+ raise Signal .make (T .TypeError , arith .op , f"Operator '{ arith .op } ' not supported for strings." )
540
540
541
541
if settings .optimize and isinstance (a , objects .ValueInstance ) and isinstance (b , objects .ValueInstance ):
542
542
# Local folding for better performance (optional, for better performance)
@@ -691,7 +691,7 @@ def compile_to_inst(state: State, rps: ast.ParameterizedSqlCode):
691
691
assert t [0 ] == '$'
692
692
if t == '$self' :
693
693
if self_table is None :
694
- raise exc . Signal .make (T .TypeError , rps , f"$self is only available for queries that return a table" )
694
+ raise Signal .make (T .TypeError , rps , f"$self is only available for queries that return a table" )
695
695
inst = self_table
696
696
else :
697
697
obj = state .get_var (t [1 :])
@@ -783,7 +783,7 @@ def compile_to_inst(state: State, sel: ast.Selection):
783
783
else :
784
784
for i , c in enumerate (conds ):
785
785
if not c .type <= T .bool :
786
- raise exc . Signal .make (T .TypeError , sel .conds [i ], f"Selection expected boolean, got { c .type } " )
786
+ raise Signal .make (T .TypeError , sel .conds [i ], f"Selection expected boolean, got { c .type } " )
787
787
788
788
code = sql .table_selection (table , [c .code for c in conds ])
789
789
@@ -794,7 +794,7 @@ def compile_to_inst(state: State, param: ast.Parameter):
794
794
if state .access_level == state .AccessLevels .COMPILE :
795
795
if param .type <= T .struct :
796
796
# TODO why can't I just make an instance?
797
- raise exc . InsufficientAccessLevel ("Structs not supported yet" )
797
+ raise InsufficientAccessLevel ("Structs not supported yet" )
798
798
return make_instance (sql .Parameter (param .type , param .name ), param .type , [])
799
799
800
800
return state .get_var (param .name )
@@ -815,7 +815,7 @@ def compile_to_inst(state: State, attr: ast.Attr):
815
815
inst = evaluate (state , attr .expr )
816
816
try :
817
817
return evaluate (state , inst .get_attr (attr .name ))
818
- except exc . pql_AttributeError as e :
818
+ except pql_AttributeError as e :
819
819
raise Signal .make (T .AttributeError , attr , e .message )
820
820
821
821
@@ -828,7 +828,7 @@ def _apply_type_generics(state, gen_type, type_names):
828
828
if not isinstance (o , Type ):
829
829
if isinstance (o .code , sql .Parameter ):
830
830
# XXX hacky test, hacky solution
831
- raise exc . InsufficientAccessLevel ()
831
+ raise InsufficientAccessLevel ()
832
832
raise Signal .make (T .TypeError , None , f"Generics expression expected a type, got '{ o } '." )
833
833
834
834
if len (type_objs ) > 1 :
0 commit comments