Skip to content

refactor: remove dead predicate .sql() path; hoist import; escape Literal repr - #4

Merged
Xof merged 1 commit into
mainfrom
refactor/remove-dead-predicate-sql
Jun 21, 2026
Merged

refactor: remove dead predicate .sql() path; hoist import; escape Literal repr#4
Xof merged 1 commit into
mainfrom
refactor/remove-dead-predicate-sql

Conversation

@Xof

@Xof Xof commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

P3 dead code & cleanup (closes D1, D2, D3)

D1 — remove dead, dialect-blind Predicate.sql() family

Predicate.sql(), CompoundPredicate.sql(), and NotPredicate.sql() were
only ever called by each other — nothing outside the predicate hierarchy
invoked them. The real compile path is Compiler._compile_predicate. The dead
methods hardcoded ? placeholders and unqualified column names, contradicting
the "all SQL flows through the Dialect" invariant and trapping any maintainer
who reached for pred.sql(). All three removed; the public
BaseRelation.sql() (which goes through the compiler) is unaffected.

D2 — hoist function-local import

Compiler._compile_predicate did from .predicates import SQL_OPERATORS
inside the function, though predicates is already imported at module top.
Hoisted into the top-level import.

D3 — escape Literal.__repr__

A string literal containing " rendered unbalanced in algebra notation
(f'"{value}"'). Now escapes the embedded quote. Plain strings are
unchanged (city="London"), and the stale comment that referenced the
removed Predicate.sql() is corrected.

Tests

TestPredicateDeadCodeRemoval: embedded-quote literal renders balanced;
plain strings/numbers unchanged; predicate classes expose no .sql();
end-to-end AND/NOT selections still compile through the real path.

Local gate green: ruff, mypy, pytest (110 passed, 15 skipped).

…eral repr

D1: Predicate.sql(), CompoundPredicate.sql(), and NotPredicate.sql() were
dead and dialect-blind — only ever called by each other, hardcoding "?"
placeholders and unqualified column names, contradicting the Dialect
invariant the real compile path (Compiler._compile_predicate) upholds.
Remove all three; the public BaseRelation.sql() is unaffected.

D2: Hoist SQL_OPERATORS into the module-level predicates import and drop the
function-local import in Compiler._compile_predicate.

D3: Literal.__repr__ now escapes embedded double-quotes so a string value
containing one renders balanced in algebra notation; the stale comment that
referenced the removed Predicate.sql() is updated.

Adds TestPredicateDeadCodeRemoval. Closes D1, D2, D3.
@Xof
Xof merged commit 0539eed into main Jun 21, 2026
5 checks passed
@Xof
Xof deleted the refactor/remove-dead-predicate-sql branch June 21, 2026 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant