Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further annotate sqlalchemy.engine and collections #6680

Merged
merged 24 commits into from
Jan 9, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
15 changes: 15 additions & 0 deletions stubs/SQLAlchemy/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# stub-only module
sqlalchemy.dbapi

# wrong argument name in implementation ("self" instead of "cls")
sqlalchemy.engine.URL.__new__
sqlalchemy.engine.url.URL.__new__
Expand Down Expand Up @@ -25,6 +28,8 @@ sqlalchemy.testing.util.resolve_lambda
sqlalchemy.util.WeakSequence.__init__

# not always present
sqlalchemy.engine.Engine.logging_name # initialized if not None
sqlalchemy.engine.base.Engine.logging_name # initialized if not None
sqlalchemy.testing.util.non_refcount_gc_collect

# replaced at runtime
Expand Down Expand Up @@ -103,6 +108,16 @@ sqlalchemy.orm.strategy_options.Load.undefer
sqlalchemy.orm.strategy_options.Load.undefer_group
sqlalchemy.orm.strategy_options.Load.with_expression

# abstract fields not present at runtime
sqlalchemy.engine.Transaction.connection
sqlalchemy.engine.Transaction.is_active
sqlalchemy.engine.base.Transaction.connection
sqlalchemy.engine.base.Transaction.is_active

# initialized to None during class construction, but overridden during __init__()
sqlalchemy.engine.Connection.engine
sqlalchemy.engine.base.Connection.engine

# unclear problems
sqlalchemy.sql.elements.quoted_name.lower
sqlalchemy.sql.elements.quoted_name.upper
Expand Down
29 changes: 17 additions & 12 deletions stubs/SQLAlchemy/sqlalchemy/cimmutabledict.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
class immutabledict:
def __len__(self) -> int: ...
def __getitem__(self, __item): ...
def __iter__(self): ...
def union(self, **kwargs): ...
def merge_with(self, *args): ...
def keys(self): ...
def __contains__(self, __item): ...
def items(self): ...
def values(self): ...
def get(self, __key, __default=...): ...
def __reduce__(self): ...
from _typeshed import SupportsKeysAndGetItem
from collections.abc import Iterable
from typing import Generic, TypeVar, overload

_KT = TypeVar("_KT")
_KT2 = TypeVar("_KT2")
_VT = TypeVar("_VT")
_VT2 = TypeVar("_VT2")

class immutabledict(dict[_KT, _VT], Generic[_KT, _VT]):
@overload
def union(self, __dict: dict[_KT2, _VT2]) -> immutabledict[_KT | _KT2, _VT | _VT2]: ...
@overload
def union(self, __dict: None = ..., **kw: SupportsKeysAndGetItem[_KT2, _VT2]) -> immutabledict[_KT | _KT2, _VT | _VT2]: ...
def merge_with(
self, *args: SupportsKeysAndGetItem[_KT | _KT2, _VT2] | Iterable[tuple[_KT2, _VT2]] | None
) -> immutabledict[_KT | _KT2, _VT | _VT2]: ...
36 changes: 36 additions & 0 deletions stubs/SQLAlchemy/sqlalchemy/dbapi.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# TODO: Tempory copy of _typeshed.dbapi, until that file is available in all typecheckers.
Akuli marked this conversation as resolved.
Show resolved Hide resolved
# Does not exist at runtime.

from collections.abc import Mapping, Sequence
from typing import Any, Protocol

DBAPITypeCode = Any | None
# Strictly speaking, this should be a Sequence, but the type system does
# not support fixed-length sequences.
DBAPIColumnDescription = tuple[str, DBAPITypeCode, int | None, int | None, int | None, int | None, bool | None]

class DBAPIConnection(Protocol):
def close(self) -> object: ...
def commit(self) -> object: ...
# optional:
# def rollback(self) -> Any: ...
def cursor(self) -> DBAPICursor: ...

class DBAPICursor(Protocol):
@property
def description(self) -> Sequence[DBAPIColumnDescription] | None: ...
@property
def rowcount(self) -> int: ...
# optional:
# def callproc(self, __procname: str, __parameters: Sequence[Any] = ...) -> Sequence[Any]: ...
def close(self) -> object: ...
def execute(self, __operation: str, __parameters: Sequence[Any] | Mapping[str, Any] = ...) -> object: ...
def executemany(self, __operation: str, __seq_of_parameters: Sequence[Sequence[Any]]) -> object: ...
def fetchone(self) -> Sequence[Any] | None: ...
def fetchmany(self, __size: int = ...) -> Sequence[Sequence[Any]]: ...
def fetchall(self) -> Sequence[Sequence[Any]]: ...
# optional:
# def nextset(self) -> None | Literal[True]: ...
arraysize: int
def setinputsizes(self, __sizes: Sequence[DBAPITypeCode | int | None]) -> object: ...
def setoutputsize(self, __size: int, __column: int = ...) -> object: ...
2 changes: 1 addition & 1 deletion stubs/SQLAlchemy/sqlalchemy/dialects/firebird/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class FBIdentifierPreparer(sql.compiler.IdentifierPreparer):
class FBExecutionContext(default.DefaultExecutionContext):
def fire_sequence(self, seq, type_): ...

class FBDialect(default.DefaultDialect):
class FBDialect(default.DefaultDialect): # type: ignore[misc]
name: str
supports_statement_cache: bool
max_identifier_length: int
Expand Down
2 changes: 1 addition & 1 deletion stubs/SQLAlchemy/sqlalchemy/dialects/firebird/fdb.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .kinterbasdb import FBDialect_kinterbasdb

class FBDialect_fdb(FBDialect_kinterbasdb):
class FBDialect_fdb(FBDialect_kinterbasdb): # type: ignore[misc]
Akuli marked this conversation as resolved.
Show resolved Hide resolved
supports_statement_cache: bool
def __init__(self, enable_rowcount: bool = ..., retaining: bool = ..., **kwargs) -> None: ...
@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class FBExecutionContext_kinterbasdb(FBExecutionContext):
@property
def rowcount(self): ...

class FBDialect_kinterbasdb(FBDialect):
class FBDialect_kinterbasdb(FBDialect): # type: ignore[misc]
driver: str
supports_statement_cache: bool
supports_sane_rowcount: bool
Expand Down
2 changes: 1 addition & 1 deletion stubs/SQLAlchemy/sqlalchemy/dialects/mssql/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class MSIdentifierPreparer(compiler.IdentifierPreparer):
def __init__(self, dialect) -> None: ...
def quote_schema(self, schema, force: Any | None = ...): ...

class MSDialect(default.DefaultDialect):
class MSDialect(default.DefaultDialect): # type: ignore[misc]
name: str
supports_statement_cache: bool
supports_default_values: bool
Expand Down
2 changes: 1 addition & 1 deletion stubs/SQLAlchemy/sqlalchemy/dialects/mssql/mxodbc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class _VARBINARY_mxodbc(VARBINARY):

class MSExecutionContext_mxodbc(MSExecutionContext_pyodbc): ...

class MSDialect_mxodbc(MxODBCConnector, MSDialect):
class MSDialect_mxodbc(MxODBCConnector, MSDialect): # type: ignore[misc]
supports_statement_cache: bool
colspecs: Any
description_encoding: Any
Expand Down
2 changes: 1 addition & 1 deletion stubs/SQLAlchemy/sqlalchemy/dialects/mssql/pymssql.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class _MSNumeric_pymssql(Numeric):
class MSIdentifierPreparer_pymssql(MSIdentifierPreparer):
def __init__(self, dialect) -> None: ...

class MSDialect_pymssql(MSDialect):
class MSDialect_pymssql(MSDialect): # type: ignore[misc]
supports_statement_cache: bool
supports_native_decimal: bool
driver: str
Expand Down
2 changes: 1 addition & 1 deletion stubs/SQLAlchemy/sqlalchemy/dialects/mssql/pyodbc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class MSExecutionContext_pyodbc(MSExecutionContext):
def pre_exec(self) -> None: ...
def post_exec(self) -> None: ...

class MSDialect_pyodbc(PyODBCConnector, MSDialect):
class MSDialect_pyodbc(PyODBCConnector, MSDialect): # type: ignore[misc]
supports_statement_cache: bool
supports_sane_rowcount_returning: bool
colspecs: Any
Expand Down
2 changes: 1 addition & 1 deletion stubs/SQLAlchemy/sqlalchemy/dialects/mysql/aiomysql.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class AsyncAdapt_aiomysql_dbapi:
def __init__(self, aiomysql, pymysql) -> None: ...
def connect(self, *arg, **kw): ...

class MySQLDialect_aiomysql(MySQLDialect_pymysql):
class MySQLDialect_aiomysql(MySQLDialect_pymysql): # type: ignore[misc]
driver: str
supports_statement_cache: bool
supports_server_side_cursors: bool
Expand Down
2 changes: 1 addition & 1 deletion stubs/SQLAlchemy/sqlalchemy/dialects/mysql/asyncmy.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class AsyncAdapt_asyncmy_dbapi:
def __init__(self, asyncmy, pymysql) -> None: ...
def connect(self, *arg, **kw): ...

class MySQLDialect_asyncmy(MySQLDialect_pymysql):
class MySQLDialect_asyncmy(MySQLDialect_pymysql): # type: ignore[misc]
driver: str
supports_statement_cache: bool
supports_server_side_cursors: bool
Expand Down
2 changes: 1 addition & 1 deletion stubs/SQLAlchemy/sqlalchemy/dialects/mysql/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class MySQLIdentifierPreparer(compiler.IdentifierPreparer):
class MariaDBIdentifierPreparer(MySQLIdentifierPreparer):
reserved_words: Any

class MySQLDialect(default.DefaultDialect):
class MySQLDialect(default.DefaultDialect): # type: ignore[misc]
logger: Any
name: str
supports_statement_cache: bool
Expand Down
2 changes: 1 addition & 1 deletion stubs/SQLAlchemy/sqlalchemy/dialects/mysql/cymysql.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from .mysqldb import MySQLDialect_mysqldb
class _cymysqlBIT(BIT):
def result_processor(self, dialect, coltype): ...

class MySQLDialect_cymysql(MySQLDialect_mysqldb):
class MySQLDialect_cymysql(MySQLDialect_mysqldb): # type: ignore[misc]
driver: str
supports_statement_cache: bool
description_encoding: Any
Expand Down
2 changes: 1 addition & 1 deletion stubs/SQLAlchemy/sqlalchemy/dialects/mysql/mariadb.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from typing import Any

from .base import MySQLDialect

class MariaDBDialect(MySQLDialect):
class MariaDBDialect(MySQLDialect): # type: ignore[misc]
is_mariadb: bool
supports_statement_cache: bool
name: str
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MySQLExecutionContext_mariadbconnector(MySQLExecutionContext):

class MySQLCompiler_mariadbconnector(MySQLCompiler): ...

class MySQLDialect_mariadbconnector(MySQLDialect):
class MySQLDialect_mariadbconnector(MySQLDialect): # type: ignore[misc]
driver: str
supports_statement_cache: bool
supports_unicode_statements: bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MySQLIdentifierPreparer_mysqlconnector(MySQLIdentifierPreparer): ...
class _myconnpyBIT(BIT):
def result_processor(self, dialect, coltype) -> None: ...

class MySQLDialect_mysqlconnector(MySQLDialect):
class MySQLDialect_mysqlconnector(MySQLDialect): # type: ignore[misc]
driver: str
supports_statement_cache: bool
supports_unicode_binds: bool
Expand Down
2 changes: 1 addition & 1 deletion stubs/SQLAlchemy/sqlalchemy/dialects/mysql/mysqldb.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MySQLExecutionContext_mysqldb(MySQLExecutionContext):

class MySQLCompiler_mysqldb(MySQLCompiler): ...

class MySQLDialect_mysqldb(MySQLDialect):
class MySQLDialect_mysqldb(MySQLDialect): # type: ignore[misc]
driver: str
supports_statement_cache: bool
supports_unicode_statements: bool
Expand Down
2 changes: 1 addition & 1 deletion stubs/SQLAlchemy/sqlalchemy/dialects/mysql/oursql.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MySQLExecutionContext_oursql(MySQLExecutionContext):
@property
def plain_query(self): ...

class MySQLDialect_oursql(MySQLDialect):
class MySQLDialect_oursql(MySQLDialect): # type: ignore[misc]
driver: str
supports_statement_cache: bool
supports_unicode_binds: bool
Expand Down
2 changes: 1 addition & 1 deletion stubs/SQLAlchemy/sqlalchemy/dialects/mysql/pymysql.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from typing import Any
from ...util import memoized_property
from .mysqldb import MySQLDialect_mysqldb

class MySQLDialect_pymysql(MySQLDialect_mysqldb):
class MySQLDialect_pymysql(MySQLDialect_mysqldb): # type: ignore[misc]
driver: str
supports_statement_cache: bool
description_encoding: Any
Expand Down
2 changes: 1 addition & 1 deletion stubs/SQLAlchemy/sqlalchemy/dialects/mysql/pyodbc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class _pyodbcTIME(TIME):
class MySQLExecutionContext_pyodbc(MySQLExecutionContext):
def get_lastrowid(self): ...

class MySQLDialect_pyodbc(PyODBCConnector, MySQLDialect):
class MySQLDialect_pyodbc(PyODBCConnector, MySQLDialect): # type: ignore[misc]
supports_statement_cache: bool
colspecs: Any
supports_unicode_statements: bool
Expand Down
2 changes: 1 addition & 1 deletion stubs/SQLAlchemy/sqlalchemy/dialects/oracle/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class OracleIdentifierPreparer(compiler.IdentifierPreparer):
class OracleExecutionContext(default.DefaultExecutionContext):
def fire_sequence(self, seq, type_): ...

class OracleDialect(default.DefaultDialect):
class OracleDialect(default.DefaultDialect): # type: ignore[misc]
name: str
supports_statement_cache: bool
supports_alter: bool
Expand Down
2 changes: 1 addition & 1 deletion stubs/SQLAlchemy/sqlalchemy/dialects/oracle/cx_oracle.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class OracleExecutionContext_cx_oracle(OracleExecutionContext):
def create_cursor(self): ...
def get_out_parameter_values(self, out_param_names): ...

class OracleDialect_cx_oracle(OracleDialect):
class OracleDialect_cx_oracle(OracleDialect): # type: ignore[misc]
supports_statement_cache: bool
statement_compiler: Any
supports_sane_rowcount: bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class AsyncAdapt_asyncpg_dbapi:
DATETIME: Any
BINARY: Any

class PGDialect_asyncpg(PGDialect):
class PGDialect_asyncpg(PGDialect): # type: ignore[misc]
driver: str
supports_statement_cache: bool
supports_unicode_statements: bool
Expand Down
2 changes: 1 addition & 1 deletion stubs/SQLAlchemy/sqlalchemy/dialects/postgresql/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class PGDeferrableConnectionCharacteristic(characteristics.ConnectionCharacteris
def set_characteristic(self, dialect, dbapi_conn, value) -> None: ...
def get_characteristic(self, dialect, dbapi_conn): ...

class PGDialect(default.DefaultDialect):
class PGDialect(default.DefaultDialect): # type: ignore[misc]
name: str
supports_statement_cache: bool
supports_alter: bool
Expand Down
2 changes: 1 addition & 1 deletion stubs/SQLAlchemy/sqlalchemy/dialects/postgresql/pg8000.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class PGCompiler_pg8000(PGCompiler):
class PGIdentifierPreparer_pg8000(PGIdentifierPreparer):
def __init__(self, *args, **kwargs) -> None: ...

class PGDialect_pg8000(PGDialect):
class PGDialect_pg8000(PGDialect): # type: ignore[misc]
driver: str
supports_statement_cache: bool
supports_unicode_statements: bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ EXECUTEMANY_BATCH: Any
EXECUTEMANY_VALUES: Any
EXECUTEMANY_VALUES_PLUS_BATCH: Any

class PGDialect_psycopg2(PGDialect):
class PGDialect_psycopg2(PGDialect): # type: ignore[misc]
driver: str
supports_statement_cache: bool
supports_unicode_statements: bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from typing import Any

from .psycopg2 import PGDialect_psycopg2

class PGDialect_psycopg2cffi(PGDialect_psycopg2):
class PGDialect_psycopg2cffi(PGDialect_psycopg2): # type: ignore[misc]
driver: str
supports_unicode_statements: bool
supports_statement_cache: bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class _PGCompiler(PGCompiler):

class _PGIdentifierPreparer(PGIdentifierPreparer): ...

class PGDialect_pygresql(PGDialect):
class PGDialect_pygresql(PGDialect): # type: ignore[misc]
driver: str
supports_statement_cache: bool
statement_compiler: Any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PGNumeric(sqltypes.Numeric):

class PGExecutionContext_pypostgresql(PGExecutionContext): ...

class PGDialect_pypostgresql(PGDialect):
class PGDialect_pypostgresql(PGDialect): # type: ignore[misc]
driver: str
supports_statement_cache: bool
supports_unicode_statements: bool
Expand Down
2 changes: 1 addition & 1 deletion stubs/SQLAlchemy/sqlalchemy/dialects/sqlite/aiosqlite.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class AsyncAdapt_aiosqlite_dbapi:
class SQLiteExecutionContext_aiosqlite(SQLiteExecutionContext):
def create_server_side_cursor(self): ...

class SQLiteDialect_aiosqlite(SQLiteDialect_pysqlite):
class SQLiteDialect_aiosqlite(SQLiteDialect_pysqlite): # type: ignore[misc]
driver: str
supports_statement_cache: bool
is_async: bool
Expand Down
2 changes: 1 addition & 1 deletion stubs/SQLAlchemy/sqlalchemy/dialects/sqlite/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class SQLiteIdentifierPreparer(compiler.IdentifierPreparer):

class SQLiteExecutionContext(default.DefaultExecutionContext): ...

class SQLiteDialect(default.DefaultDialect):
class SQLiteDialect(default.DefaultDialect): # type: ignore[misc]
name: str
supports_alter: bool
supports_unicode_statements: bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from typing import Any

from .pysqlite import SQLiteDialect_pysqlite

class SQLiteDialect_pysqlcipher(SQLiteDialect_pysqlite):
class SQLiteDialect_pysqlcipher(SQLiteDialect_pysqlite): # type: ignore[misc]
driver: str
supports_statement_cache: bool
pragmas: Any
Expand Down
2 changes: 1 addition & 1 deletion stubs/SQLAlchemy/sqlalchemy/dialects/sqlite/pysqlite.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class _SQLite_pysqliteDate(DATE):
def bind_processor(self, dialect): ...
def result_processor(self, dialect, coltype): ...

class SQLiteDialect_pysqlite(SQLiteDialect):
class SQLiteDialect_pysqlite(SQLiteDialect): # type: ignore[misc]
default_paramstyle: str
supports_statement_cache: bool
colspecs: Any
Expand Down
2 changes: 1 addition & 1 deletion stubs/SQLAlchemy/sqlalchemy/dialects/sybase/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class SybaseDDLCompiler(compiler.DDLCompiler):
class SybaseIdentifierPreparer(compiler.IdentifierPreparer):
reserved_words: Any

class SybaseDialect(default.DefaultDialect):
class SybaseDialect(default.DefaultDialect): # type: ignore[misc]
name: str
supports_unicode_statements: bool
supports_sane_rowcount: bool
Expand Down
2 changes: 1 addition & 1 deletion stubs/SQLAlchemy/sqlalchemy/dialects/sybase/mxodbc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from sqlalchemy.dialects.sybase.base import SybaseDialect, SybaseExecutionContex

class SybaseExecutionContext_mxodbc(SybaseExecutionContext): ...

class SybaseDialect_mxodbc(MxODBCConnector, SybaseDialect):
class SybaseDialect_mxodbc(MxODBCConnector, SybaseDialect): # type: ignore[misc]
supports_statement_cache: bool

dialect = SybaseDialect_mxodbc
Loading