Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ optional-dependencies.all = [
"sqlalchemy-cratedb[vector]",
]
optional-dependencies.develop = [
"mypy<1.20",
"poethepoet<1",
"pyproject-fmt<3",
"ruff<0.16",
"ty==0.0.42",
"validate-pyproject<1",
]
optional-dependencies.doc = [
Expand Down Expand Up @@ -187,18 +187,6 @@ lint.per-file-ignores."tests/*" = [
"W293", # Blank line contains whitespace
]

[tool.mypy]
mypy_path = "src"
packages = [ "sqlalchemy_cratedb" ]
exclude = []
namespace_packages = true
explicit_package_bases = true
ignore_missing_imports = true
check_untyped_defs = true
implicit_optional = true
install_types = true
non_interactive = true

[tool.pytest]
ini_options.minversion = "2.0"
ini_options.testpaths = [
Expand Down Expand Up @@ -259,7 +247,7 @@ tasks.lint = [
{ cmd = "ruff format --check" },
{ cmd = "ruff check" },
{ cmd = "validate-pyproject pyproject.toml" },
# { cmd = "mypy" },
{ cmd = "ty check src/" },
]
tasks.release = [
{ cmd = "python -m build" },
Expand Down
4 changes: 2 additions & 2 deletions src/sqlalchemy_cratedb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@


try:
from importlib.metadata import PackageNotFoundError, version
from importlib.metadata import PackageNotFoundError, version # ty: ignore[unresolved-import]
except (ImportError, ModuleNotFoundError): # pragma:nocover
from importlib_metadata import ( # type: ignore[assignment,no-redef,unused-ignore]
from importlib_metadata import ( # ty: ignore[unresolved-import]
PackageNotFoundError,
version,
)
Expand Down
19 changes: 10 additions & 9 deletions src/sqlalchemy_cratedb/compat/api13.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"""

import collections.abc as collections_abc
import typing as t

from sqlalchemy import exc
from sqlalchemy.sql import Select
Expand All @@ -42,7 +43,7 @@

# `_distill_params_20` copied from SA14's `sqlalchemy.engine.{base,util}`.
_no_tuple = ()
_no_kw = immutabledict()
_no_kw: immutabledict = immutabledict()


def _distill_params_20(params):
Expand Down Expand Up @@ -87,11 +88,11 @@ def monkeypatch_add_exec_driver_sql():
from sqlalchemy.engine.base import Connection, Engine

# Add `exec_driver_sql` method to SA's `Connection` and `Engine` classes.
Connection.exec_driver_sql = exec_driver_sql
Engine.exec_driver_sql = exec_driver_sql
Connection.exec_driver_sql = exec_driver_sql # ty: ignore[invalid-assignment]
Engine.exec_driver_sql = exec_driver_sql # ty: ignore[unresolved-attribute]


def select_sa14(*columns, **kw) -> Select:
def select_sa14(*columns, **kw) -> Select[t.Any]:
"""
Adapt SA14/SA20's calling semantics of `sql.select()` to SA13.

Expand All @@ -110,7 +111,7 @@ def select_sa14(*columns, **kw) -> Select:
)
columns, whereclause = columns
kw["whereclause"] = whereclause
return original_select(columns, **kw)
return original_select(columns, **kw) # ty: ignore[no-matching-overload]


def monkeypatch_amend_select_sa14():
Expand All @@ -123,9 +124,9 @@ def monkeypatch_amend_select_sa14():
"""
import sqlalchemy

sqlalchemy.select = select_sa14
sqlalchemy.sql.select = select_sa14
sqlalchemy.sql.expression.select = select_sa14
sqlalchemy.select = select_sa14 # ty: ignore[invalid-assignment]
sqlalchemy.sql.select = select_sa14 # ty: ignore[invalid-assignment]
sqlalchemy.sql.expression.select = select_sa14 # ty: ignore[invalid-assignment]


@property
Expand All @@ -149,4 +150,4 @@ def connectionfairy_driver_connection_sa14(self):
def monkeypatch_add_connectionfairy_driver_connection():
import sqlalchemy.pool.base

sqlalchemy.pool.base._ConnectionFairy.driver_connection = connectionfairy_driver_connection_sa14
sqlalchemy.pool.base._ConnectionFairy.driver_connection = connectionfairy_driver_connection_sa14 # ty: ignore[invalid-assignment]
20 changes: 10 additions & 10 deletions src/sqlalchemy_cratedb/compat/core10.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
REQUIRED,
_create_bind_param,
_extend_values_for_multiparams,
_get_multitable_params,
_get_stmt_parameters_params,
_get_multitable_params, # ty: ignore[unresolved-import]
_get_stmt_parameters_params, # ty: ignore[unresolved-import]
_key_getters_for_crud_column,
_scan_cols,
_scan_insert_from_select_cols,
Expand All @@ -36,13 +36,13 @@


class CrateCompilerSA10(CrateCompiler):
def returning_clause(self, stmt, returning_cols):
def returning_clause(self, stmt, returning_cols): # ty: ignore[invalid-method-override]
"""
Generate RETURNING clause, PostgreSQL-compatible.
"""
return PGCompiler.returning_clause(self, stmt, returning_cols)
return PGCompiler.returning_clause(self, stmt, returning_cols) # ty: ignore[missing-argument]

def visit_update(self, update_stmt, **kw):
def visit_update(self, update_stmt, **kw): # ty: ignore[invalid-method-override]
"""
used to compile <sql.expression.Update> expressions
Parts are taken from the SQLCompiler base class.
Expand Down Expand Up @@ -93,7 +93,7 @@ def visit_update(self, update_stmt, **kw):

if self.returning or update_stmt._returning:
if not self.returning:
self.returning = update_stmt._returning
self.returning = update_stmt._returning # ty: ignore[invalid-assignment]
if self.returning_precedes_values:
text += " " + self.returning_clause(update_stmt, self.returning)

Expand Down Expand Up @@ -154,7 +154,7 @@ def _get_crud_params(compiler, stmt, **kw):
_column_as_key,
_getattr_col_key,
_col_bind_name,
) = _key_getters_for_crud_column(compiler, stmt)
) = _key_getters_for_crud_column(compiler, stmt) # ty: ignore[missing-argument]

# if we have statement parameters - set defaults in the
# compiled params
Expand Down Expand Up @@ -192,7 +192,7 @@ def _get_crud_params(compiler, stmt, **kw):
)

if compiler.isinsert and stmt.select_names:
_scan_insert_from_select_cols(
_scan_insert_from_select_cols( # ty: ignore[missing-argument]
compiler,
stmt,
parameters,
Expand All @@ -204,7 +204,7 @@ def _get_crud_params(compiler, stmt, **kw):
kw,
)
else:
_scan_cols(
_scan_cols( # ty: ignore[missing-argument]
compiler,
stmt,
parameters,
Expand Down Expand Up @@ -248,6 +248,6 @@ def _get_crud_params(compiler, stmt, **kw):
"""

if stmt._has_multi_parameters:
values = _extend_values_for_multiparams(compiler, stmt, values, kw)
values = _extend_values_for_multiparams(compiler, stmt, values, kw) # ty: ignore[invalid-argument-type,missing-argument]

return values
17 changes: 10 additions & 7 deletions src/sqlalchemy_cratedb/compat/core14.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
# with Crate these terms will supersede the license and you may use the
# software solely pursuant to the terms of the relevant commercial agreement.

import typing as t

import sqlalchemy as sa
from sqlalchemy.dialects.postgresql.base import PGCompiler
from sqlalchemy.sql import selectable
Expand All @@ -37,13 +39,13 @@


class CrateCompilerSA14(CrateCompiler):
def returning_clause(self, stmt, returning_cols):
def returning_clause(self, stmt, returning_cols): # ty: ignore[invalid-method-override]
"""
Generate RETURNING clause, PostgreSQL-compatible.
"""
return PGCompiler.returning_clause(self, stmt, returning_cols)
return PGCompiler.returning_clause(self, stmt, returning_cols) # ty: ignore[missing-argument]

def visit_update(self, update_stmt, **kw):
def visit_update(self, update_stmt, **kw): # ty: ignore[invalid-method-override]
compile_state = update_stmt._compile_state_factory(update_stmt, self, **kw)
update_stmt = compile_state.statement

Expand Down Expand Up @@ -196,6 +198,7 @@ def _get_crud_params(compiler, stmt, compile_state, **kw):
for c in stmt.table.columns
]

spd: t.Iterable
if compile_state._has_multi_parameters:
spd = compile_state._multi_parameters[0]
stmt_parameter_tuples = list(spd.items())
Expand All @@ -206,7 +209,7 @@ def _get_crud_params(compiler, stmt, compile_state, **kw):
spd = compile_state._dict_parameters
stmt_parameter_tuples = list(spd.items())
else:
stmt_parameter_tuples = spd = None
stmt_parameter_tuples = spd = []

# if we have statement parameters - set defaults in the
# compiled params
Expand Down Expand Up @@ -251,7 +254,7 @@ def _get_crud_params(compiler, stmt, compile_state, **kw):
)

if compile_state.isinsert and stmt._select_names:
_scan_insert_from_select_cols(
_scan_insert_from_select_cols( # ty: ignore[missing-argument]
compiler,
stmt,
compile_state,
Expand All @@ -264,7 +267,7 @@ def _get_crud_params(compiler, stmt, compile_state, **kw):
kw,
)
else:
_scan_cols(
_scan_cols( # ty: ignore[missing-argument]
compiler,
stmt,
compile_state,
Expand Down Expand Up @@ -314,7 +317,7 @@ def _get_crud_params(compiler, stmt, compile_state, **kw):
stmt,
compile_state,
values,
_column_as_key,
_column_as_key, # ty: ignore[invalid-argument-type]
kw,
)
elif not values and compiler.for_executemany and compiler.dialect.supports_default_metavalue:
Expand Down
12 changes: 6 additions & 6 deletions src/sqlalchemy_cratedb/compat/core20.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def visit_update(self, update_stmt, visiting_cte=None, **kw):

# SA 2.1 renamed update_limit_clause to update_post_criteria_clause.
if SA_VERSION >= SA_2_1:
limit_clause = self.update_post_criteria_clause(update_stmt, **kw)
limit_clause = self.update_post_criteria_clause(update_stmt, **kw) # ty: ignore[unresolved-attribute]
else:
limit_clause = self.update_limit_clause(update_stmt)
if limit_clause:
Expand Down Expand Up @@ -416,14 +416,14 @@ def _get_crud_params(
compiler,
stmt,
compile_state,
cast(
cast( # ty: ignore[invalid-argument-type]
"Sequence[_CrudParamElementStr]",
values,
values, # ty: ignore[invalid-argument-type]
),
cast("Callable[..., str]", _column_as_key),
cast("Callable[..., str]", _column_as_key), # ty: ignore[invalid-argument-type]
kw,
)
return _CrudParams(values, multi_extended_values)
return _CrudParams(values, multi_extended_values) # ty: ignore[invalid-argument-type]
elif not values and compiler.for_executemany and compiler.dialect.supports_default_metavalue:
# convert an "INSERT DEFAULT VALUES"
# into INSERT (firstcol) VALUES (DEFAULT) which can be turned
Expand All @@ -438,4 +438,4 @@ def _get_crud_params(
)
]

return _CrudParams(values, [])
return _CrudParams(values, []) # ty: ignore[invalid-argument-type]
12 changes: 7 additions & 5 deletions src/sqlalchemy_cratedb/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
from collections import defaultdict

import sqlalchemy as sa
import sqlalchemy.event
import sqlalchemy.exc
from sqlalchemy.dialects.postgresql.base import RESERVED_WORDS as POSTGRESQL_RESERVED_WORDS
from sqlalchemy.dialects.postgresql.base import PGCompiler
from sqlalchemy.sql import compiler
Expand Down Expand Up @@ -143,7 +145,7 @@

return colspec

def visit_computed_column(self, generated):
def visit_computed_column(self, generated): # ty: ignore[invalid-method-override]
if generated.persisted is False:
raise sa.exc.CompileError(
"Virtual computed columns are not supported, set 'persisted' to None or True"
Expand Down Expand Up @@ -276,7 +278,7 @@
"""
Use native `ILIKE` operator, like PostgreSQL's `PGCompiler`.
"""
if self.dialect.has_ilike_operator():
if self.dialect.has_ilike_operator(): # ty: ignore[unresolved-attribute]
return element.element._compiler_dispatch(self, **kw)
else:
return super().visit_ilike_case_insensitive_operand(element, **kw)
Expand All @@ -290,7 +292,7 @@
"""
if binary.modifiers.get("escape", None) is not None:
raise NotImplementedError("Unsupported feature: ESCAPE is not supported")
if self.dialect.has_ilike_operator():
if self.dialect.has_ilike_operator(): # ty: ignore[unresolved-attribute]
return "%s ILIKE %s" % (
self.process(binary.left, **kw),
self.process(binary.right, **kw),
Expand All @@ -307,7 +309,7 @@
"""
if binary.modifiers.get("escape", None) is not None:
raise NotImplementedError("Unsupported feature: ESCAPE is not supported")
if self.dialect.has_ilike_operator():
if self.dialect.has_ilike_operator(): # ty: ignore[unresolved-attribute]
return "%s NOT ILIKE %s" % (
self.process(binary.left, **kw),
self.process(binary.right, **kw),
Expand All @@ -319,7 +321,7 @@
"""
Generate OFFSET / LIMIT clause, PostgreSQL-compatible.
"""
return PGCompiler.limit_clause(self, select, **kw)
return PGCompiler.limit_clause(self, select, **kw) # ty: ignore[invalid-argument-type]

def for_update_clause(self, select, **kw):
# CrateDB does not support the `INSERT ... FOR UPDATE` clause.
Expand Down
Loading
Loading