@@ -86,7 +86,7 @@ def db_query(state: State, sql_code, subqueries=None):
86
86
try :
87
87
return state .db .query (sql_code , subqueries , state = state )
88
88
except exc .DatabaseQueryError as e :
89
- raise Signal .make (T .DbQueryError , state , None , e .args [0 ]) from e
89
+ raise Signal .make (T .DbQueryError , None , e .args [0 ]) from e
90
90
91
91
def drop_table (state , table_type ):
92
92
name ,= table_type .options ['name' ].parts
@@ -115,7 +115,7 @@ def _execute(state: State, table_def: ast.TableDef):
115
115
116
116
if any (isinstance (c , ast .Ellipsis ) for c in table_def .columns ):
117
117
# XXX why must it? just ensure it appears once
118
- raise Signal .make (T .SyntaxError , state , table_def , "Ellipsis must appear at the end" )
118
+ raise Signal .make (T .SyntaxError , table_def , "Ellipsis must appear at the end" )
119
119
120
120
# Create type and a corresponding table in the database
121
121
t = resolve (state , table_def )
@@ -140,12 +140,12 @@ def _execute(state: State, table_def: ast.TableDef):
140
140
for e_name , e1_type in t .elems .items ():
141
141
142
142
if e_name not in cur_type .elems :
143
- raise Signal .make (T .TypeError , state , table_def , f"Column '{ e_name } ' defined, but doesn't exist in database." )
143
+ raise Signal .make (T .TypeError , table_def , f"Column '{ e_name } ' defined, but doesn't exist in database." )
144
144
145
145
e2_type = cur_type .elems [e_name ]
146
146
# XXX use can_cast() instead of hardcoding it
147
147
# if not (e1_type <= e2_type or (e1_type <= T.t_id and e2_type <= T.int)):
148
- # raise Signal.make(T.TypeError, state, table_def, f"Cannot cast column '{e_name}' from type '{e2_type}' to '{e1_type}'")
148
+ # raise Signal.make(T.TypeError, table_def, f"Cannot cast column '{e_name}' from type '{e2_type}' to '{e1_type}'")
149
149
150
150
inst = objects .new_table (t , db_name , select_fields = True )
151
151
else :
@@ -168,7 +168,7 @@ def _set_value(state: State, name: ast.Name, value):
168
168
169
169
@dy
170
170
def _set_value (state : State , attr : ast .Attr , value ):
171
- raise Signal .make (T .NotImplementedError , state , attr , f"Cannot set attribute for { attr .expr .repr (state )} " )
171
+ raise Signal .make (T .NotImplementedError , attr , f"Cannot set attribute for { attr .expr .repr (state )} " )
172
172
173
173
@dy
174
174
def _execute (state : State , var_def : ast .SetValue ):
@@ -188,7 +188,7 @@ def _copy_rows(state: State, target_name: ast.Name, source: objects.TableInstanc
188
188
params = dict (table_params (target .type ))
189
189
for p in params :
190
190
if p not in source .type .elems :
191
- raise Signal .make (T .TypeError , state , source , f"Missing column '{ p } ' in { source .type } " )
191
+ raise Signal .make (T .TypeError , source , f"Missing column '{ p } ' in { source .type } " )
192
192
193
193
primary_keys , columns = table_flat_for_insert (target .type )
194
194
@@ -249,7 +249,7 @@ def _execute(state: State, p: ast.Assert):
249
249
s = (' %s ' % p .cond .op ).join (str (evaluate (state , a ).repr (state )) for a in p .cond .args )
250
250
else :
251
251
s = p .cond .repr (state )
252
- raise Signal .make (T .AssertError , state , p .cond , f"Assertion failed: { s } " )
252
+ raise Signal .make (T .AssertError , p .cond , f"Assertion failed: { s } " )
253
253
254
254
@dy
255
255
def _execute (state : State , cb : ast .CodeBlock ):
@@ -297,7 +297,7 @@ def import_module(state, r):
297
297
if module_path .exists ():
298
298
break
299
299
else :
300
- raise Signal .make (T .ImportError , state , r , "Cannot find module" )
300
+ raise Signal .make (T .ImportError , r , "Cannot find module" )
301
301
302
302
from .interpreter import Interpreter # XXX state.new_interp() ?
303
303
i = Interpreter (state .db , state .fmt , use_core = r .use_core )
@@ -415,7 +415,7 @@ def simplify(state: State, obj: ast.Or):
415
415
a , b = evaluate (state , obj .args )
416
416
_ , (ta , tb ) = objects .unvectorize_args ([a ,b ])
417
417
if ta .type != tb .type :
418
- raise Signal .make (T .TypeError , state , obj , f"'or' operator requires both arguments to be of the same type, but got '{ ta .type } ' and '{ tb .type } '." )
418
+ raise Signal .make (T .TypeError , obj , f"'or' operator requires both arguments to be of the same type, but got '{ ta .type } ' and '{ tb .type } '." )
419
419
try :
420
420
if test_nonzero (state , a ):
421
421
return a
@@ -429,7 +429,7 @@ def simplify(state: State, obj: ast.And):
429
429
a , b = evaluate (state , obj .args )
430
430
_ , (ta , tb ) = objects .unvectorize_args ([a ,b ])
431
431
if ta .type != tb .type :
432
- raise Signal .make (T .TypeError , state , obj , f"'or' operator requires both arguments to be of the same type, but got '{ ta .type } ' and '{ tb .type } '." )
432
+ raise Signal .make (T .TypeError , obj , f"'or' operator requires both arguments to be of the same type, but got '{ ta .type } ' and '{ tb .type } '." )
433
433
try :
434
434
if not test_nonzero (state , a ):
435
435
return a
@@ -455,7 +455,7 @@ def simplify(state: State, funccall: ast.FuncCall):
455
455
456
456
if isinstance (func , objects .UnknownInstance ):
457
457
# evaluate(state, [a.value for a in funccall.args])
458
- raise Signal .make (T .TypeError , state , funccall .func , f"Error: Object of type '{ func .type } ' is not callable" )
458
+ raise Signal .make (T .TypeError , funccall .func , f"Error: Object of type '{ func .type } ' is not callable" )
459
459
460
460
args = funccall .args
461
461
if isinstance (func , Type ):
@@ -464,7 +464,7 @@ def simplify(state: State, funccall: ast.FuncCall):
464
464
func = state .get_var ('cast' )
465
465
466
466
if not isinstance (func , objects .Function ):
467
- raise Signal .make (T .TypeError , state , funccall .func , f"Error: Object of type '{ func .type } ' is not callable" )
467
+ raise Signal .make (T .TypeError , funccall .func , f"Error: Object of type '{ func .type } ' is not callable" )
468
468
469
469
state .stacktrace .append (funccall .text_ref )
470
470
try :
@@ -497,7 +497,7 @@ def eval_func_call(state, func, args):
497
497
# TODO cast?
498
498
# if p.type and not a.type <= T.union[p.type, T.vectorized[p.type]]:
499
499
if p .type and not a .type <= p .type :
500
- raise Signal .make (T .TypeError , state , func , f"Argument #{ i } of '{ func .name } ' is of type '{ a .type } ', expected '{ p .type } '" )
500
+ raise Signal .make (T .TypeError , func , f"Argument #{ i } of '{ func .name } ' is of type '{ a .type } ', expected '{ p .type } '" )
501
501
args [p .name ] = a
502
502
503
503
@@ -583,7 +583,7 @@ def apply_database_rw(state: State, o: ast.One):
583
583
obj = evaluate (state , o .expr )
584
584
if obj .type <= T .struct :
585
585
if len (obj .attrs ) != 1 :
586
- raise Signal .make (T .ValueError , state , o , f"'one' expected a struct with a single attribute, got { len (obj .attrs )} " )
586
+ raise Signal .make (T .ValueError , o , f"'one' expected a struct with a single attribute, got { len (obj .attrs )} " )
587
587
x ,= obj .attrs .values ()
588
588
return x
589
589
@@ -594,10 +594,10 @@ def apply_database_rw(state: State, o: ast.One):
594
594
rows = localize (state , table ) # Must be 1 row
595
595
if len (rows ) == 0 :
596
596
if not o .nullable :
597
- raise Signal .make (T .ValueError , state , o , "'one' expected a single result, got an empty expression" )
597
+ raise Signal .make (T .ValueError , o , "'one' expected a single result, got an empty expression" )
598
598
return objects .null
599
599
elif len (rows ) > 1 :
600
- raise Signal .make (T .ValueError , state , o , "'one' expected a single result, got more" )
600
+ raise Signal .make (T .ValueError , o , "'one' expected a single result, got more" )
601
601
602
602
row ,= rows
603
603
rowtype = T .row [table .type ]
@@ -620,15 +620,15 @@ def apply_database_rw(state: State, d: ast.Delete):
620
620
table = evaluate (state , cond_table )
621
621
622
622
if not (table .type <= T .table ):
623
- raise Signal .make (T .TypeError , state , d .table , f"Expected a table. Got: { table .type } " )
623
+ raise Signal .make (T .TypeError , d .table , f"Expected a table. Got: { table .type } " )
624
624
625
625
if not 'name' in table .type .options :
626
- raise Signal .make (T .ValueError , state , d .table , "Cannot delete. Table is not persistent" )
626
+ raise Signal .make (T .ValueError , d .table , "Cannot delete. Table is not persistent" )
627
627
628
628
rows = list (localize (state , table ))
629
629
if rows :
630
630
if 'id' not in rows [0 ]:
631
- raise Signal .make (T .TypeError , state , d , "Delete error: Table does not contain id" )
631
+ raise Signal .make (T .TypeError , d , "Delete error: Table does not contain id" )
632
632
633
633
ids = [row ['id' ] for row in rows ]
634
634
@@ -645,14 +645,14 @@ def apply_database_rw(state: State, u: ast.Update):
645
645
table = evaluate (state , u .table )
646
646
647
647
if not (table .type <= T .table ):
648
- raise Signal .make (T .TypeError , state , u .table , f"Expected a table. Got: { table .type } " )
648
+ raise Signal .make (T .TypeError , u .table , f"Expected a table. Got: { table .type } " )
649
649
650
650
if not 'name' in table .type .options :
651
- raise Signal .make (T .ValueError , state , u .table , "Cannot update: Table is not persistent" )
651
+ raise Signal .make (T .ValueError , u .table , "Cannot update: Table is not persistent" )
652
652
653
653
for f in u .fields :
654
654
if not f .name :
655
- raise Signal .make (T .SyntaxError , state , f , f"Update requires that all fields have a name" )
655
+ raise Signal .make (T .SyntaxError , f , f"Update requires that all fields have a name" )
656
656
657
657
# TODO verify table is concrete (i.e. lvalue, not a transitory expression)
658
658
@@ -663,9 +663,9 @@ def apply_database_rw(state: State, u: ast.Update):
663
663
rows = list (localize (state , table ))
664
664
if rows :
665
665
if 'id' not in rows [0 ]:
666
- raise Signal .make (T .TypeError , state , u , "Update error: Table does not contain id" )
666
+ raise Signal .make (T .TypeError , u , "Update error: Table does not contain id" )
667
667
if not set (proj ) < set (rows [0 ]):
668
- raise Signal .make (T .TypeError , state , u , "Update error: Not all keys exist in table" )
668
+ raise Signal .make (T .TypeError , u , "Update error: Not all keys exist in table" )
669
669
670
670
ids = [row ['id' ] for row in rows ]
671
671
@@ -683,7 +683,7 @@ def apply_database_rw(state: State, new: ast.NewRows):
683
683
obj = state .get_var (new .type )
684
684
685
685
if len (new .args ) > 1 :
686
- raise Signal .make (T .NotImplementedError , state , new , "Not yet implemented" ) #. Requires column-wise table concat (use join and enum)")
686
+ raise Signal .make (T .NotImplementedError , new , "Not yet implemented" ) #. Requires column-wise table concat (use join and enum)")
687
687
688
688
if isinstance (obj , objects .UnknownInstance ):
689
689
arg ,= new .args
@@ -728,9 +728,9 @@ def _destructure_param_match(state, ast_node, param_match):
728
728
if (k .type <= T .struct ):
729
729
names = [name for name , t in flatten_type (k .orig , [k .name ])]
730
730
if not isinstance (v , list ):
731
- raise Signal .make (T .TypeError , state , ast_node , f"Parameter { k .name } received a bad value: { v } (expecting a struct or a list)" )
731
+ raise Signal .make (T .TypeError , ast_node , f"Parameter { k .name } received a bad value: { v } (expecting a struct or a list)" )
732
732
if len (v ) != len (names ):
733
- raise Signal .make (T .TypeError , state , ast_node , f"Parameter { k .name } received a bad value (size of { len (names )} )" )
733
+ raise Signal .make (T .TypeError , ast_node , f"Parameter { k .name } received a bad value (size of { len (names )} )" )
734
734
yield from safezip (names , v )
735
735
else :
736
736
yield k .name , v
@@ -784,7 +784,7 @@ def create_exception(state, msg):
784
784
return res
785
785
786
786
if not isinstance (obj , objects .TableInstance ):
787
- raise Signal .make (T .TypeError , state , new , f"'new' expects a table or exception, instead got { obj .repr (state )} " )
787
+ raise Signal .make (T .TypeError , new , f"'new' expects a table or exception, instead got { obj .repr (state )} " )
788
788
789
789
table = obj
790
790
# TODO assert tabletype is a real table and not a query (not transient), otherwise new is meaningless
@@ -969,7 +969,7 @@ def new_table_from_expr(state, name, expr, const, temporary):
969
969
return objects .TableInstance .make (sql .null , expr .type , [])
970
970
971
971
if 'id' in elems and not const :
972
- raise Signal .make (T .NameError , state , None , "Field 'id' already exists. Rename it, or use 'const table' to copy it as-is." )
972
+ raise Signal .make (T .NameError , None , "Field 'id' already exists. Rename it, or use 'const table' to copy it as-is." )
973
973
974
974
table = T .table (dict (elems ), name = Id (name ), pk = [] if const else [['id' ]], temporary = temporary )
975
975
@@ -987,7 +987,7 @@ def new_table_from_expr(state, name, expr, const, temporary):
987
987
988
988
@dy
989
989
def cast_to_python (state , obj ):
990
- raise Signal .make (T .TypeError , state , None , f"Unexpected value: { pql_repr (state , obj .type , obj )} " )
990
+ raise Signal .make (T .TypeError , None , f"Unexpected value: { pql_repr (state , obj .type , obj )} " )
991
991
992
992
@dy
993
993
def cast_to_python (state , obj : ast .Ast ):
@@ -999,7 +999,7 @@ def cast_to_python(state, obj: objects.AbsInstance):
999
999
# if state.access_level <= state.AccessLevels.QUERY:
1000
1000
if obj .type <= T .vectorized :
1001
1001
raise exc .InsufficientAccessLevel (state .access_level )
1002
- # raise Signal.make(T.CastError, state, None, f"Internal error. Cannot cast vectorized (i.e. projected) obj: {obj}")
1002
+ # raise Signal.make(T.CastError, None, f"Internal error. Cannot cast vectorized (i.e. projected) obj: {obj}")
1003
1003
res = localize (state , obj )
1004
1004
if obj .type == T .float :
1005
1005
res = float (res )
0 commit comments