Skip to content

refactor: tighten adapter typing and core cleanup#545

Merged
cofin merged 23 commits into
mainfrom
chore/cleanup
Jun 29, 2026
Merged

refactor: tighten adapter typing and core cleanup#545
cofin merged 23 commits into
mainfrom
chore/cleanup

Conversation

@cofin

@cofin cofin commented Jun 28, 2026

Copy link
Copy Markdown
Member

Description

This PR tightens runtime typing, optional dependency boundaries, and core execution hot paths while preserving public APIs.

  • Moves driver-specific runtime aliases and exception classes into adapter _typing modules, then reuses those exports from driver implementations instead of importing provider packages inside methods.
  • Keeps BigQuery, Spanner, Oracle, asyncpg, Cockroach asyncpg, and psqlpy runtime handling patchable and optional-dependency safe.
  • Restores psqlpy public runtime aliases so PsqlpyConnection, PsqlpyConfig.connection_type, and signature namespace resolution use psqlpy.Connection when the extra is installed, with a fallback when it is absent.
  • Narrows adapter connection and close handling for ADBC, Arrow ODBC, BigQuery, DuckDB, MSSQL, MySQL-family, Oracle, psqlpy, and Spanner code paths.
  • Optimizes core splitter, parameter, compiler/type-detection, filter, hashing, and cache hot paths without changing statement output or public behavior.
  • Preserves runtime-safe Final annotations in compiled core modules.
  • Consolidates duplicated core helper implementations while keeping public classes, module paths, and documented helper APIs stable.
  • Adds additive exports and smoke coverage for externally callable core helpers.
  • Fixes Spanner GoogleSQL single-quote string literal parsing, the MySQL splitter terminator type annotation needed by the mypyc wheel build, the compiled StackResult MyPyC crash, and the Spanner tokenizer docs type-alias resolution.
  • Renames tests and comments so they describe behavior instead of internal planning labels.

Closes

Closes #546
Closes #547
Closes #548
Closes #549
Closes #550
Closes #551
Closes #552

Validation

  • make clean
  • make install-compiled
  • uv run python tools/scripts/mypyc_smoke.py --require-compiled
  • make docs
  • make lint
  • make type-check
  • uv run pytest tests/unit/core/test_result.py tests/unit/adapters/test_spanner/test_dialect.py -q --tb=short
  • uv run pytest tests/unit/adapters/test_spanner/test_dialect.py::test_string_literals_single_quote tests/unit/adapters/test_spanner/test_dialect.py::test_string_literals_unicode tests/unit/adapters/test_spanner/test_dialect.py::test_dialect_inheritance -q --tb=short
  • uv run mypy tests/unit/core/test_splitter.py
  • uv run pytest tests/unit/core/test_splitter.py -q --tb=short
  • uv run mypy sqlspec/core/splitter.py tests/unit/core/test_splitter.py
  • uv run mypyc --check-untyped-defs --no-warn-unused-configs sqlspec/core/splitter.py
  • uv run pytest tests/unit/adapters/test_asyncpg/test_driver.py tests/unit/adapters/test_asyncpg/test_config.py tests/unit/adapters/test_psqlpy/test_core.py tests/unit/adapters/test_psqlpy/test_config.py tests/unit/adapters/test_cockroach_asyncpg/test_core.py tests/unit/adapters/test_cockroach_asyncpg/test_config.py tests/unit/adapters/test_bigquery/test_storage_write_api.py tests/unit/adapters/test_bigquery/test_core.py tests/unit/adapters/test_oracledb/test_pipeline_helpers.py tests/unit/adapters/test_oracledb/test_core_driver_features.py tests/unit/adapters/test_oracledb/test_lob_coercion.py tests/unit/adapters/test_spanner/test_driver.py tests/unit/adapters/test_spanner/test_load_from_arrow_mutations.py tests/unit/adapters/test_spanner/test_batch_write_api.py -q --tb=short

@codecov-commenter

codecov-commenter commented Jun 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.42660% with 156 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.52%. Comparing base (f5393d8) to head (e23600f).

Files with missing lines Patch % Lines
sqlspec/builder/_case.py 0.00% 30 Missing ⚠️
sqlspec/adapters/psqlpy/adk/store.py 22.85% 26 Missing and 1 partial ⚠️
sqlspec/core/parameters/_transformers.py 55.81% 13 Missing and 6 partials ⚠️
sqlspec/core/splitter.py 91.89% 5 Missing and 4 partials ⚠️
sqlspec/core/filters.py 91.11% 2 Missing and 6 partials ⚠️
sqlspec/adapters/oracledb/driver.py 36.36% 5 Missing and 2 partials ⚠️
sqlspec/core/cache.py 78.57% 4 Missing and 2 partials ⚠️
sqlspec/adapters/asyncpg/driver.py 28.57% 4 Missing and 1 partial ⚠️
sqlspec/adapters/mysqlconnector/adk/store.py 73.33% 4 Missing ⚠️
sqlspec/adapters/psqlpy/driver.py 42.85% 3 Missing and 1 partial ⚠️
... and 19 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #545      +/-   ##
==========================================
- Coverage   75.55%   75.52%   -0.04%     
==========================================
  Files         444      445       +1     
  Lines       58791    58630     -161     
  Branches     9132     9021     -111     
==========================================
- Hits        44418    44278     -140     
+ Misses      11500    11497       -3     
+ Partials     2873     2855      -18     
Flag Coverage Δ
integration 59.54% <57.08%> (+0.19%) ⬆️
py3.10 73.88% <79.54%> (-0.05%) ⬇️
py3.11 73.90% <79.54%> (-0.05%) ⬇️
py3.12 73.89% <79.54%> (-0.05%) ⬇️
py3.13 73.89% <79.54%> (-0.05%) ⬇️
py3.14 74.72% <80.30%> (-0.04%) ⬇️
unit 61.34% <75.15%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
sqlspec/__init__.py 88.46% <ø> (ø)
sqlspec/adapters/arrow_odbc/config.py 82.60% <100.00%> (ø)
sqlspec/adapters/asyncpg/_typing.py 94.59% <100.00%> (+0.15%) ⬆️
sqlspec/adapters/bigquery/_typing.py 80.43% <100.00%> (+1.86%) ⬆️
sqlspec/adapters/cockroach_asyncpg/_typing.py 93.10% <100.00%> (+0.24%) ⬆️
sqlspec/adapters/duckdb/_typing.py 93.93% <100.00%> (-0.18%) ⬇️
sqlspec/adapters/duckdb/config.py 95.56% <100.00%> (ø)
sqlspec/adapters/duckdb/data_dictionary.py 34.48% <ø> (ø)
sqlspec/adapters/duckdb/driver.py 85.05% <ø> (ø)
sqlspec/adapters/duckdb/pool.py 79.03% <ø> (ø)
... and 64 more

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cofin cofin changed the title fix: restore psqlpy runtime aliases refactor: tighten adapter typing and core cleanup Jun 29, 2026
@cofin cofin merged commit 1998faf into main Jun 29, 2026
28 checks passed
@cofin cofin deleted the chore/cleanup branch June 29, 2026 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment