Skip to content

Commit

Permalink
Properly handle unused vars
Browse files Browse the repository at this point in the history
  • Loading branch information
msullivan committed Feb 20, 2024
1 parent 2d22bfe commit 29bfc42
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
13 changes: 12 additions & 1 deletion edb/pgsql/compiler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

from edb.pgsql import ast as pgast
from edb.pgsql import params as pgparams
from edb.pgsql import types as pgtypes

from . import config as _config_compiler # NOQA
from . import expr as _expr_compiler # NOQA
Expand Down Expand Up @@ -148,7 +149,17 @@ def compile_ir_to_sql_tree(
assert isinstance(qtree, pgast.Query)
clauses.fini_toplevel(qtree, ctx)

detached_params = [p for _, p in sorted(ctx.detached_params.items())]
if detach_params:
detached_params_idx = {
ctx.argmap[param.name].index: (
pgtypes.pg_type_from_ir_typeref(
param.ir_type.base_type or param.ir_type))
for param in ctx.env.query_params
if not param.sub_params
}
else:
detached_params_idx = {}
detached_params = [p for _, p in sorted(detached_params_idx.items())]

except errors.EdgeDBError:
# Don't wrap propertly typed EdgeDB errors into
Expand Down
6 changes: 0 additions & 6 deletions edb/pgsql/compiler/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,6 @@ class CompilerContextLevel(compiler.ContextLevel):
#: needed by DML.
shapes_needed_by_dml: Set[irast.Set]

#: Aggregated output of detached SQL parameters (position integer) and
#: their SQL types (qualified names tuple)
detached_params: Dict[int, Tuple[str, ...]]

def __init__(
self,
prevlevel: Optional[CompilerContextLevel],
Expand Down Expand Up @@ -358,7 +354,6 @@ def __init__(
self.shapes_needed_by_dml = set()

self.trigger_mode = False
self.detached_params = {}

else:
self.env = prevlevel.env
Expand Down Expand Up @@ -398,7 +393,6 @@ def __init__(
self.external_rels = prevlevel.external_rels

self.trigger_mode = prevlevel.trigger_mode
self.detached_params = prevlevel.detached_params

if mode is ContextSwitchMode.SUBSTMT:
if self.pending_query is not None:
Expand Down
4 changes: 1 addition & 3 deletions edb/pgsql/compiler/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ def compile_Parameter(
index = ctx.argmap[expr.name].index
result = pgast.ParamRef(number=index, nullable=not expr.required)
if ctx.env.detach_params:
# Extract the type casting to build a stored function later
ctx.detached_params[index] = pg_types.pg_type_from_ir_typeref(
expr.typeref.base_type or expr.typeref)
# XXX: Do we need this?
return result

return pgast.TypeCast(
Expand Down

0 comments on commit 29bfc42

Please sign in to comment.