From 1abddec29e834977ede1a6e2ca6cb526e6bad38b Mon Sep 17 00:00:00 2001 From: Ali Hamdan Date: Sat, 23 Sep 2023 18:40:29 +0200 Subject: [PATCH] Fix --- .ignore | 1 - django-stubs/db/backends/utils.pyi | 2 +- poetry.lock | 15 +- psycopg2-stubs/__init__.pyi | 74 ------- psycopg2-stubs/extensions.pyi | 297 ----------------------------- psycopg2-stubs/extras.pyi | 291 ---------------------------- psycopg2-stubs/py.typed | 0 psycopg2-stubs/sql.pyi | 57 ------ psycopg2-stubs/tz.pyi | 13 -- pyproject.toml | 2 +- tests/trout/models.py | 168 ---------------- typings/psycopg2 | 1 - 12 files changed, 14 insertions(+), 907 deletions(-) delete mode 100644 psycopg2-stubs/__init__.pyi delete mode 100644 psycopg2-stubs/extensions.pyi delete mode 100644 psycopg2-stubs/extras.pyi delete mode 100644 psycopg2-stubs/py.typed delete mode 100644 psycopg2-stubs/sql.pyi delete mode 100644 psycopg2-stubs/tz.pyi delete mode 120000 typings/psycopg2 diff --git a/.ignore b/.ignore index b07cd0f98..a22906928 100644 --- a/.ignore +++ b/.ignore @@ -1,2 +1 @@ django-stubs -psycopg2-stubs diff --git a/django-stubs/db/backends/utils.pyi b/django-stubs/db/backends/utils.pyi index ac8d6f03d..43778ffe1 100644 --- a/django-stubs/db/backends/utils.pyi +++ b/django-stubs/db/backends/utils.pyi @@ -6,7 +6,7 @@ from typing import IO, Any from typing_extensions import Literal from uuid import UUID -import psycopg2 +import psycopg2.extensions from django.db.backends.postgresql.base import DatabaseWrapper from psycopg2.extensions import Column diff --git a/poetry.lock b/poetry.lock index b860635c2..7e951200a 100644 --- a/poetry.lock +++ b/poetry.lock @@ -275,8 +275,6 @@ dmypy = ["psutil (>=4.0)"] install-types = ["pip"] python2 = ["typed-ast (>=1.4.0,<2)"] reports = ["lxml"] -python2 = ["typed-ast (>=1.4.0,<2)"] -dmypy = ["psutil (>=4.0)"] [[package]] name = "mypy-extensions" @@ -568,6 +566,17 @@ files = [ {file = "typed_ast-1.5.4.tar.gz", hash = "sha256:39e21ceb7388e4bb37f4c679d72707ed46c2fbf2a5609b8b8ebc4b067d977df2"}, ] +[[package]] +name = "types-psycopg2" +version = "2.9.21.13" +description = "Typing stubs for psycopg2" +optional = false +python-versions = "*" +files = [ + {file = "types-psycopg2-2.9.21.13.tar.gz", hash = "sha256:662e6d7b03d89e3bac6aaf2892a97f2cca287f861e693dcefc96ca2e996642c5"}, + {file = "types_psycopg2-2.9.21.13-py3-none-any.whl", hash = "sha256:3ee7c32918d18c133bd0b4d92db7e1bd4c5f78a2ff217d74d4e3b6a09c95d506"}, +] + [[package]] name = "types-pytz" version = "2021.3.8" @@ -633,4 +642,4 @@ testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more [metadata] lock-version = "2.0" python-versions = "^3.7" -content-hash = "52fb8b5bbef796fb426395df7d591d06ef51edd2a5133e6b02710f9895278e07" +content-hash = "71293af57fb7853bb135fb07b16a2d1c509fa23de7fd19bc5e7d862e1bf5dc64" diff --git a/psycopg2-stubs/__init__.pyi b/psycopg2-stubs/__init__.pyi deleted file mode 100644 index c048e1a94..000000000 --- a/psycopg2-stubs/__init__.pyi +++ /dev/null @@ -1,74 +0,0 @@ -from typing import Any - -from psycopg2 import _psycopg as _psycopg -from psycopg2 import errors as errors -from psycopg2 import extensions as extensions -from psycopg2 import extras as extras -from psycopg2 import sql as sql -from psycopg2 import tz as tz - -paramstyle: str -threadsafety: int - -def connect( - dsn: str | None = ..., - connection_factory: Any | None = ..., - cursor_factor: Any | None = ..., - async_: bool = ..., - dbname: str = ..., - user: str = ..., - password: str = ..., - host: str = ..., - port: str = ..., - **kwargs: str -) -> extensions.connection: ... - -class Warning(Exception): ... - -class Error(Exception): - @property - def pgerror(self) -> str | None: ... - @property - def pgcode(self) -> str | None: ... - @property - def cursor(self) -> extensions.cursor | None: ... - @property - def diag(self) -> extensions.Diagnostics: ... - -class InterfaceError(Error): ... -class DatabaseError(Error): ... -class DataError(DatabaseError): ... -class OperationalError(DatabaseError): ... -class IntegrityError(DatabaseError): ... -class InternalError(DatabaseError): ... -class ProgrammingError(DatabaseError): ... -class NotSupportedError(DatabaseError): ... - -class Date: - def __init__(self, year: int, month: int, day: int) -> None: ... - -class Time: - def __init__(self, hour: int, minute: int, second: int) -> None: ... - -class Timestamp: - def __init__( - self, year: int, month: int, day: int, hour: int, minute: int, second: int - ) -> None: ... - -class DateFromTicks: - def __init__(self, ticks: int) -> None: ... - -class TimeFromTicks: - def __init__(self, ticks: int) -> None: ... - -class TimestampFromTicks: - def __init__(self, ticks: int) -> None: ... - -class Binary: - def __init__(self, string: bytes) -> None: ... - -class STRING: ... -class BINARY: ... -class NUMBER: ... -class DATETIME: ... -class ROWID: ... diff --git a/psycopg2-stubs/extensions.pyi b/psycopg2-stubs/extensions.pyi deleted file mode 100644 index b833853e6..000000000 --- a/psycopg2-stubs/extensions.pyi +++ /dev/null @@ -1,297 +0,0 @@ -from __future__ import annotations - -from collections.abc import Iterable, Iterator, Mapping, Sequence -from datetime import datetime -from decimal import Decimal -from typing import IO, Any, NamedTuple -from typing_extensions import Literal -from uuid import UUID - -ISOLATION_LEVEL_AUTOCOMMIT: Literal[0] -ISOLATION_LEVEL_READ_UNCOMMITTED: Literal[4] -ISOLATION_LEVEL_READ_COMMITTED: Literal[1] -ISOLATION_LEVEL_REPEATABLE_READ: Literal[2] -ISOLATION_LEVEL_SERIALIZABLE: Literal[3] -ISOLATION_LEVEL_DEFAULT: None - -STATUS_SETUP: Literal[0] -STATUS_READY: Literal[1] -STATUS_BEGIN: Literal[2] -STATUS_SYNC: Literal[3] -STATUS_ASYNC: Literal[4] -STATUS_PREPARED: Literal[5] - -STATUS_IN_TRANSACTION: Literal[2] - -POLL_OK: Literal[0] -POLL_READ: Literal[1] -POLL_WRITE: Literal[2] -POLL_ERROR: Literal[3] - -_PollConstants = Literal[0, 1, 2, 3] - -TRANSACTION_STATUS_IDLE: Literal[0] -TRANSACTION_STATUS_ACTIVE: Literal[1] -TRANSACTION_STATUS_INTRANS: Literal[2] -TRANSACTION_STATUS_INERROR: Literal[3] -TRANSACTION_STATUS_UNKNOWN: Literal[4] - -_TransactionStatus = Literal[0, 1, 2, 3, 4] - -_Mixed = None | bool | int | float | Decimal | str | bytes | datetime | UUID -_SQLType = _Mixed | Sequence[_Mixed] | Mapping[str, _Mixed] - -class cursor: - def __init__(self, conn: _connection) -> None: ... - @property - def description(self) -> tuple[Column, ...] | None: ... - def close(self) -> None: ... - @property - def closed(self) -> bool: ... - @property - def connection(self) -> _connection: ... - @property - def name(self) -> str | None: ... - scrollable: bool | None - withhold: bool - def execute( - self, - query: str, - vars: Sequence[_SQLType] | Mapping[str, _SQLType] | None = ..., - ) -> None: ... - def executemany( - self, - query: str, - vars_list: Sequence[Sequence[_SQLType] | Mapping[str, _SQLType]], - ) -> None: ... - def callproc( - self, - procname: str, - parameters: Sequence[_SQLType] | Mapping[str, _SQLType] = ..., - ) -> None: ... - def mogrify( - self, - operation: str, - parameters: Sequence[_SQLType] | Mapping[str, _SQLType] | None = ..., - ) -> bytes: ... - def setinputsizes(self, sizes: int) -> None: ... - def fetchone(self) -> tuple[Any, ...] | None: ... - def fetchmany(self, size: int = ...) -> list[tuple[Any, ...]]: ... - def fetchall(self) -> list[tuple[Any, ...]]: ... - def scroll( - self, value: int, mode: Literal["relative", "absolute"] = ... - ) -> None: ... - arraysize: int - itersize: int - @property - def rowcount(self) -> int: ... - @property - def rownumber(self) -> int: ... - @property - def lastrowid(self) -> int | None: ... - @property - def query(self) -> str | None: ... - @property - def statusmessage(self) -> str | None: ... - def cast(self, oid: int, s: str) -> Any: ... - tzinfo_factory: Any - def nextset(self) -> None: ... - def setoutputsize(self, size: int, column: int = ...) -> None: ... - def copy_from( - self, - file: IO[str], - table: str, - sep: str = ..., - null: str = ..., - size: int = ..., - columns: Iterable[str] | None = ..., - ) -> None: ... - def copy_to( - self, - file: IO[str], - table: str, - sep: str = ..., - null: str = ..., - columns: str | None = ..., - ) -> None: ... - def copy_expert(self, sql: str, file: IO[str], size: int = ...) -> None: ... - def __enter__(self) -> cursor: ... - def __exit__(self, exc_type: None, exc_value: None, traceback: None) -> None: ... - def __iter__(self) -> Iterator[tuple[Any, ...]]: ... - def __next__(self) -> tuple[Any, ...]: ... - -_cursor = cursor -_IsolationLevelsCodes = Literal[0, 1, 2, 3, 4] - -_IsolationLevels = Literal[ - "READ UNCOMMIITED", - "READ COMMITTED", - "REPEATABLE READ", - "SERIALIZABLE", - _IsolationLevelsCodes, -] - -class connection: - def __init__(self, dsn: str) -> None: ... - def cursor( - self, - name: str | None = ..., - cursor_factory: Any | None = ..., - scrollable: bool | None = ..., - withhold: bool = ..., - ) -> _cursor: ... - def commit(self) -> None: ... - def rollback(self) -> None: ... - def close(self) -> None: ... - def xid(self, format_id: str, gtrid: str, bqual: Any) -> Xid: ... - def tpc_begin(self, xid: str | Xid) -> None: ... - def tpc_preparse(self) -> None: ... - def tpc_commit(self, xid: str | Xid = ...) -> None: ... - def tpc_rollback(self, xid: str | Xid = ...) -> None: ... - def tpc_recover(self) -> None: ... - @property - def closed(self) -> int: ... - def cancel(self) -> None: ... - def reset(self) -> None: ... - @property - def dsn(self) -> str: ... - def set_session( - self, - isolation_level: _IsolationLevels | None = ..., - readonly: bool | None = ..., - deferrable: bool | None = ..., - autocommit: bool | None = ..., - ) -> None: ... - autocommit: bool - isolation_level: _IsolationLevelsCodes - readonly: bool | None - deferrable: bool | None - def set_isolation_level(self, level: _IsolationLevelsCodes) -> None: ... - encoding: str - def set_client_encoding(self, enc: str) -> None: ... - @property - def notices(self) -> list[str]: ... - notifies: list[Notify] - cursor_factory: Any - info: ConnectionInfo - @property - def status(self) -> int: ... - def lobject( - self, - oid: int = ..., - mode: str = ..., - new_oid: int = ..., - new_file: Any = ..., - lobject_factory: Any = ..., - ) -> _lobject: ... - @property - def async_(self) -> Literal[0, 1]: ... - def poll(self) -> _PollConstants: ... - def fileno(self) -> Any: ... - def isexecuting(self) -> bool: ... - pgconn_ptr: Any - def get_native_connection(self) -> Any: ... - def get_transaction_status(self) -> _TransactionStatus: ... - @property - def protocol_version(self) -> int: ... - @property - def server_version(self) -> int: ... - def get_backend_pid(self) -> int: ... - def get_parameter_status(self, parameter: str) -> str | None: ... - def get_dsn_parameters(self) -> dict[str, str]: ... - def __enter__(self) -> connection: ... - def __exit__(self, exc_type: None, exc_value: None, traceback: None) -> None: ... - -class Xid: ... -class lobject: ... - -_lobject = lobject - -class Notify: - def __init__(self, pid: str, channel: str, payload: str) -> None: ... - channel: str - payload: str - pid: str - -_connection = connection - -class ConnectionInfo: - def __init__(self, connection: connection) -> None: ... - dbname: str - user: str - password: str - host: str - port: int - options: str - dsn_parameters: dict[str, str] - status: int - transaction_status: int - def parameter_status(self, name: str) -> str: ... - protocol_version: int - server_version: int - error_message: str | None - socket: int - backend_pid: int - needs_password: bool - used_password: bool - ssl_in_use: bool - def ssl_attribute(self, name: str) -> str: ... - ssl_attribute_names: list[str] - -class Column(NamedTuple): - name: str | None - type_code: int | None - display_size: int | None - internal_size: int | None - precision: int | None - scale: int | None - null_ok: None - table_column: str | None - table_oid: int | None - -class Diagnostics: - @property - def column_name(self) -> str | None: ... - @property - def constraint_name(self) -> str | None: ... - @property - def context(self) -> str | None: ... - @property - def datatype_name(self) -> str | None: ... - @property - def internal_position(self) -> str | None: ... - @property - def internal_query(self) -> str | None: ... - @property - def message_detail(self) -> str | None: ... - @property - def message_hint(self) -> str | None: ... - @property - def message_primary(self) -> str | None: ... - @property - def schema_name(self) -> str | None: ... - @property - def severity(self) -> str | None: ... - @property - def severity_nonlocalized(self) -> str | None: ... - @property - def source_file(self) -> str | None: ... - @property - def source_function(self) -> str | None: ... - @property - def source_line(self) -> str | None: ... - @property - def sqlstate(self) -> str | None: ... - @property - def statement_position(self) -> str | None: ... - @property - def table_name(self) -> str | None: ... - -def parse_dsn(dsn: str) -> dict[str, str]: ... -def quote_ident(str: str, scope: connection | cursor) -> str: ... -def encrypt_password( - password: str, - user: str, - scope: connection | cursor | None = ..., - algorithm: str | None = ..., -) -> str: ... diff --git a/psycopg2-stubs/extras.pyi b/psycopg2-stubs/extras.pyi deleted file mode 100644 index 678fda5c9..000000000 --- a/psycopg2-stubs/extras.pyi +++ /dev/null @@ -1,291 +0,0 @@ -from collections import OrderedDict -from collections.abc import Iterator, Mapping, Sequence -from re import Pattern -from typing import Any, NamedTuple, overload -from typing_extensions import Literal, Protocol - -from psycopg2._psycopg import ReplicationConnection as _replicationConnection -from psycopg2._psycopg import ReplicationCursor as _replicationCursor -from psycopg2._range import DateRange as DateRange -from psycopg2._range import DateTimeTZRange as DateTimeTZRange -from psycopg2._range import NumericRange as NumericRange -from psycopg2._range import Range as Range -from psycopg2.extensions import _SQLType -from psycopg2.extensions import connection as _connection -from psycopg2.extensions import cursor as _cursor - -class DictCursorBase(_cursor): - _query_executed: bool - _prefetch: bool - row_factory: Any - def __init__(self, *args: Any, row_factory: Any | None, **kwargs: Any) -> None: ... - def fetchone(self) -> tuple[Any, ...] | None: ... - def fetchmany(self, size: int | None = ...) -> list[tuple[Any, ...]]: ... - def fetchall(self) -> list[tuple[Any, ...]]: ... - def __iter__(self) -> Iterator[tuple[Any, ...]]: ... - -class DictConnection(_connection): - def cursor( - self, *args: Any, cursor_factory: DictCursorBase | None = ..., **kwargs: Any - ) -> _cursor: ... - -class DictCursor(DictCursorBase): - index: OrderedDict[str, int] - _query_executed: bool - def __init__(self, *args: Any, **kwargs: Any) -> None: ... - def execute( - self, - query: str, - vars: Sequence[_SQLType] | Mapping[str, _SQLType] | None = ..., - ) -> None: ... - def callproc( - self, - procname: str, - parameters: Sequence[_SQLType] | Mapping[str, _SQLType] = ..., - ) -> None: ... - -class DictRow(list[Any]): - _index: OrderedDict[str, int] - def __init__(self, cursor: DictCursor) -> None: ... - def __getitem__(self, x: str | int | slice) -> Any: ... # type: ignore [override] - def __setitem__(self, x: str | int | slice, v: Any) -> None: ... # type: ignore [override] - def items(self) -> Iterator[tuple[str, Any]]: ... - def keys(self) -> Iterator[str]: ... - def values(self) -> Iterator[Any]: ... - def get(self, x: str | int | slice, default: Any | None = ...) -> Any | None: ... - def copy(self) -> OrderedDict[str, Any]: ... # type: ignore [override] - def __contains__(self, x: str) -> bool: ... # type: ignore [override] - def __getstate__(self) -> tuple[Any, OrderedDict[str, int]]: ... - def __setstate__(self, data: tuple[Any, OrderedDict[str, int]]) -> None: ... - -class RealDictConnection(_connection): - def cursor( # type: ignore [override] - self, *args: Any, cursor_factory: RealDictCursor, **kwargs: Any - ) -> _cursor: ... - -class RealDictCursor(DictCursorBase): - column_mapping: list[Any] - _query_executed: bool - def __init__(self, *args: Any, **kwargs: Any) -> None: ... - def execute( - self, - query: str, - vars: Sequence[_SQLType] | Mapping[str, _SQLType] | None = ..., - ) -> None: ... - def callproc( - self, - procname: str, - vars: Sequence[_SQLType] | Mapping[str, _SQLType] | None = ..., - ) -> None: ... - -class RealDictRow(OrderedDict[Any, Any]): - def __init__(self, *args: Any, **kwargs: Any) -> None: ... - def __setitem__(self, key: Any, value: Any) -> None: ... - -class NamedTupleConnection(_connection): - def cursor(self, *args: Any, **kwargs: Any) -> _cursor: ... - -class NamedTupleCursor(_cursor): - Record: NamedTuple | None = ... - MAX_CACHE: int = ... - def execute( - self, - query: str, - vars: Sequence[_SQLType] | Mapping[str, _SQLType] | None = ..., - ) -> None: ... - def executemany( - self, - query: str, - vars_list: Sequence[Sequence[_SQLType] | Mapping[str, _SQLType]], - ) -> None: ... - def callproc( - self, - procname: str, - vars: Sequence[_SQLType] | Mapping[str, _SQLType] | None = ..., - ) -> None: ... - def fetchone(self) -> tuple[Any, ...] | None: ... - def fetchmany(self, size: int = ...) -> list[tuple[Any, ...]]: ... - def fetchall(self) -> list[tuple[Any, ...]]: ... - def __iter__(self) -> Iterator[tuple[Any, ...]]: ... - -class LoggingConnection(_connection): - def initialize(self, logobj: Any) -> None: ... - def filter(self, msg: Any, curs: Any) -> Any: ... - def cursor(self, *args: Any, **kwargs: Any) -> _cursor: ... - -class LoggingCursor(_cursor): - def execute( - self, - query: str, - vars: Sequence[_SQLType] | Mapping[str, _SQLType] | None = ..., - ) -> None: ... - def callproc( - self, - procname: str, - vars: Sequence[_SQLType] | Mapping[str, _SQLType] | None = ..., - ) -> None: ... - -class MinTimeLoggingConnection(LoggingConnection): - def initialize(self, logobj: Any, mintime: int = ...) -> None: ... - def filter(self, msg: Any, curs: Any) -> str | None: ... - def cursor(self, *args: Any, **kwargs: Any) -> _cursor: ... - -class MinTimeLoggingCursor(LoggingCursor): - timestamp: float - def execute( - self, - query: str, - vars: Sequence[_SQLType] | Mapping[str, _SQLType] | None = ..., - ) -> None: ... - def callproc( - self, - procname: str, - vars: Sequence[_SQLType] | Mapping[str, _SQLType] | None = ..., - ) -> None: ... - -class LogicalReplicationConnection(_replicationConnection): - def __init__(self, *args: Any, **kwargs: Any) -> None: ... - -class PhysicalReplicationConnection(_replicationConnection): - def __init__(self, *args: Any, **kwargs: Any) -> None: ... - -class StopReplication(Exception): ... - -class ReplicationCursor(_replicationCursor): - def create_replication_slot( - self, - slot_name: Any, - slot_type: Any | None = ..., - output_plugin: Any | None = ..., - ) -> None: ... - def drop_replication_slot(self, slot_name: Any) -> None: ... - def start_replication( - self, - slot_name: Any | None = ..., - slot_type: Any | None = ..., - start_lsn: int = ..., - timeline: int = ..., - options: Mapping[Any, Any] | None = ..., - decode: bool = ..., - ) -> None: ... - def fileno(self) -> Any: ... - -class UUID_adapter: - _uuid: Any - def __init__(self, uuid: Any) -> None: ... - def __conform__(self, proto: Any) -> UUID_adapter | None: ... - def getquoted(self) -> str: ... - -def register_uuid( - oids: Any | None = ..., conn_or_curs: _cursor | _connection | None = ... -) -> None: ... - -class Inet: - addr: Any - _conn: _connection - def __init__(self, addr: Any) -> None: ... - def prepare(self, conn: _connection) -> None: ... - def getquoted(self) -> bytes: ... - def __conform__(self, proto: Any) -> Inet | None: ... - -def register_inet( - oid: int | None = ..., conn_or_curs: _connection | _cursor | None = ... -) -> Inet: ... -def wait_select(conn: _connection) -> None: ... - -class HstoreAdapter: - wrapped: Any - conn: _connection - def __init__(self, wrapped: Any) -> None: ... - def prepare(self, conn: _connection) -> None: ... - def _getquoted_9(self) -> bytes: ... - getquoted = _getquoted_9 - @classmethod - def parse( - cls, s: str | None, cur: _cursor, _bsdec: Pattern[str] = ... - ) -> dict[str, str] | None: ... - @classmethod - def parse_unicode(cls, s: str | None, cur: _cursor) -> dict[str, str] | None: ... - @classmethod - def get_oids( - cls, conn_or_curs: _connection | _cursor - ) -> tuple[tuple[Any, ...], tuple[Any, ...]]: ... - -def register_hstore( - conn_or_curs: _connection | _cursor, - globally: bool = ..., - unicode: bool = ..., - oid: int | None = ..., - array_oid: int | None = ..., -) -> None: ... - -class CompositeCaster: - name: str - schema: Any | None - oid: int - array_oid: int | None - attrnames: list[Any] - attrtypes: list[Any] - typecaster: Any - array_typecaster: Any | None - def __init__( - self, - name: str, - oid: int, - attrs: Any, - array_oid: int | None = ..., - schema: Any | None = ..., - ) -> None: ... - def parse(self, s: str | None, curs: Any) -> Any: ... - def make(self, values: Any) -> Any: ... - @classmethod - def tokenize(cls, s: str) -> list[str | None]: ... - -def register_composite( - name: str, - conn_or_curs: _connection | _cursor, - globally: bool = ..., - factory: CompositeCaster | None = ..., -) -> CompositeCaster: ... - -class _CursorLike(Protocol): - @property - def connection(self) -> _connection: ... - def mogrify( - self, - operation: str, - parameters: Sequence[_SQLType] | Mapping[str, _SQLType] | None = ..., - ) -> bytes: ... - def execute( - self, - sql: str, - params: Sequence[_SQLType] | Mapping[str, _SQLType] | None = ..., - ) -> None: ... - def fetchall(self) -> list[tuple[Any, ...]]: ... - -def execute_batch( - cur: _CursorLike, - sql: str, - argslist: Sequence[Sequence[_SQLType] | Mapping[str, _SQLType]], - page_size: int = ..., -) -> None: ... -@overload -def execute_values( - cur: _CursorLike, - sql: str, - argslist: Sequence[Sequence[_SQLType] | Mapping[str, _SQLType]], - *, - template: bytes | None = ..., - page_size: int = ..., - fetch: Literal[True], -) -> list[tuple[Any, ...]]: ... -@overload -def execute_values( - cur: _CursorLike, - sql: str, - argslist: Sequence[Sequence[_SQLType] | Mapping[str, _SQLType]], - *, - template: bytes | None = ..., - page_size: int = ..., - fetch: Literal[False] = ..., -) -> None: ... diff --git a/psycopg2-stubs/py.typed b/psycopg2-stubs/py.typed deleted file mode 100644 index e69de29bb..000000000 diff --git a/psycopg2-stubs/sql.pyi b/psycopg2-stubs/sql.pyi deleted file mode 100644 index b3a81459f..000000000 --- a/psycopg2-stubs/sql.pyi +++ /dev/null @@ -1,57 +0,0 @@ -import string -from collections.abc import Iterable, Iterator -from typing import Any - -from psycopg2.extensions import _SQLType, connection -from psycopg2.extras import _CursorLike - -_formatter: string.Formatter - -_Context = connection | _CursorLike - -class Composable: - def __init__(self, wrapped: _SQLType) -> None: ... - def as_string(self, context: _Context) -> str: ... - def __add__(self, other: Any) -> Composed: ... - def __mul__(self, n: int) -> Composed: ... - def __eq__(self, other: object) -> bool: ... - def __ne__(self, other: object) -> bool: ... - -class Composed(Composable): - def __init__(self, seq: Iterable[Composable]) -> None: ... - @property - def seq(self) -> list[Composable]: ... - def as_string(self, context: _Context) -> str: ... - def __iter__(self) -> Iterator[Composable]: ... - def __add__(self, other: object) -> Composed: ... - def join(self, joiner: str | SQL) -> Composed: ... - -class SQL(Composable): - def __init__(self, string: str) -> None: ... - @property - def string(self) -> str: ... - def as_string(self, context: _Context) -> str: ... - def format(self, *args: Any, **kwargs: Any) -> Composed: ... - def join(self, seq: Iterable[Composable]) -> Composed: ... - -class Identifier(Composable): - def __init__(self, *strings: str) -> None: ... - @property - def strings(self) -> list[str]: ... - @property - def string(self) -> str: ... - def as_string(self, context: _Context) -> str: ... - -class Literal(Composable): - @property - def wrapped(self) -> Any: ... - def as_string(self, context: _Context) -> str: ... - -class Placeholder(Composable): - def __init__(self, name: str | None = ...) -> None: ... - @property - def name(self) -> str | None: ... - def as_string(self, context: _Context) -> str: ... - -NULL: SQL -DEFAULT: SQL diff --git a/psycopg2-stubs/tz.pyi b/psycopg2-stubs/tz.pyi deleted file mode 100644 index 8e4f074bd..000000000 --- a/psycopg2-stubs/tz.pyi +++ /dev/null @@ -1,13 +0,0 @@ -import datetime - -ZERO = datetime.timedelta(0) - -class FixedOffsetTimezone(datetime.tzinfo): ... # type: ignore[misc] - -STDOFFSET: datetime.timedelta -DSTOFFSET: datetime.timedelta -DSTDIFF: datetime.timedelta - -class LocalTimezone(datetime.tzinfo): ... # type: ignore[misc] - -LOCAL: LocalTimezone diff --git a/pyproject.toml b/pyproject.toml index d8f874382..bbd0dbb24 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ packages = [{ include = "django-stubs" }] [tool.poetry.dependencies] python = "^3.7" -types-psycopg2 = "^2.9.19" +types-psycopg2 = ">=2.9.21.13" [tool.poetry.dev-dependencies] black = "22.3.0" diff --git a/tests/trout/models.py b/tests/trout/models.py index 532f2f877..ce2171a65 100644 --- a/tests/trout/models.py +++ b/tests/trout/models.py @@ -1,15 +1,12 @@ # Disable because pyright is not able to understand the Meta nested class override in models. # pyright: reportIncompatibleVariableOverride=false -import sys from collections import namedtuple from datetime import time, timedelta from decimal import Decimal -from io import StringIO from typing import Any, Dict, List, Optional, Tuple, Union from uuid import UUID -import psycopg2 from django.contrib.auth.models import User as AuthUser from django.contrib.contenttypes.fields import GenericRelation from django.contrib.postgres.fields import ( @@ -43,18 +40,14 @@ require_GET, require_POST, ) -from psycopg2 import ProgrammingError, sql -from psycopg2.extensions import parse_dsn from psycopg2.extras import execute_values class User(models.Model): - pass class Post(models.Model): - pass @@ -276,7 +269,6 @@ def process_non_nullable( def main() -> None: - client = Client() res = client.post( @@ -671,7 +663,6 @@ async def main_async() -> None: def raw_database_queries() -> None: - with connection.cursor() as cursor: cursor.execute("select 1;") results = cursor.fetchall() @@ -758,134 +749,6 @@ def get_data() -> Dict[str, Dict[str, str]]: return dict(cursor.fetchall()) # type: ignore [arg-type] -def test_psycopg2() -> None: - with connection.cursor() as cursor: - comp = sql.Composed([sql.SQL("insert into "), sql.Identifier("table")]) - print(comp.as_string(cursor)) - - query = sql.SQL("select {0} from {1}").format( - sql.SQL(", ").join([sql.Identifier("foo"), sql.Identifier("bar")]), - sql.Identifier("table"), - ) - print(query.as_string(cursor)) - - snip = sql.SQL(", ").join(sql.Identifier(n) for n in ["foo", "bar", "baz"]) - print(snip.as_string(cursor)) - - query = sql.SQL("select {} from {}").format( - sql.Identifier("table", "field"), sql.Identifier("schema", "table") - ) - print(query.as_string(cursor)) - - t1 = sql.Identifier("foo") - t2 = sql.Identifier("ba'r") - t3 = sql.Identifier('ba"z') - print(sql.SQL(", ").join([t1, t2, t3]).as_string(cursor)) - - s1 = sql.Literal("foo") - s2 = sql.Literal("ba'r") - s3 = sql.Literal(42) - print(sql.SQL(", ").join([s1, s2, s3]).as_string(cursor)) - - query = sql.SQL("select {} from {}").format( - sql.Identifier("table", "field"), sql.Identifier("schema", "table") - ) - print(query.as_string(cursor)) - - names = ["foo", "bar", "baz"] - - q1 = sql.SQL("insert into table ({}) values ({})").format( - sql.SQL(", ").join(map(sql.Identifier, names)), - sql.SQL(", ").join(sql.Placeholder() * len(names)), - ) - print(q1.as_string(cursor)) - - q2 = sql.SQL("insert into table ({}) values ({})").format( - sql.SQL(", ").join(map(sql.Identifier, names)), - sql.SQL(", ").join(map(sql.Placeholder, names)), - ) - print(q2.as_string(cursor)) - - cur = cursor.cursor - cur.execute("SELECT * FROM test;") - for record in cur: - print(record) - - cur.execute("SELECT * FROM test WHERE id = %s", (3,)) - assert cur.fetchone() == (3, 42, "bar") - - cur.execute("SELECT * FROM test;") - assert cur.fetchmany(2) == [(1, 100, "abc'def"), (2, None, "dada")] - assert cur.fetchmany(2) == [(3, 42, "bar")] - assert cur.fetchmany(2) == [] - - cur.execute("SELECT * FROM test;") - assert cur.fetchall() == [ - (1, 100, "abc'def"), - (2, None, "dada"), - (3, 42, "bar"), - ] - - try: - cur.scroll(1000 * 1000) - except (ProgrammingError, IndexError) as exc: - print(exc) - - cur.arraysize = 10 - cur.itersize = 100 - - try: - cur.execute("SELECT * FROM barf") - except psycopg2.Error as e: - assert e.pgcode == "42P01" - assert e.pgerror == ( - """ -ERROR: relation "barf" does not exist -LINE 1: SELECT * FROM barf -""" - ) - - f = StringIO("42\tfoo\n74\tbar\n") - cur.copy_from(f, "test", columns=("num", "data")) - cur.execute("select * from test where id > 5;") - cur.fetchall() - cur.copy_from(f, '"TABLE"') - cur.copy_to(sys.stdout, "test", sep="|") - - cur.copy_expert("COPY test TO STDOUT WITH CSV HEADER", sys.stdout) - - conn = psycopg2.connect("dbname=test user=postgres password=secret") - conn = psycopg2.connect(dbname="test", user="postgres", password="secret") - - print(conn.isolation_level) - - with conn: - with conn.cursor() as curs: - curs.execute("select 1") - - with conn: - with conn.cursor() as curs: - curs.execute("select 2") - conn.close() - - assert parse_dsn("dbname=test user=postgres password=secret") == { - "password": "secret", - "user": "postgres", - "dbname": "test", - } - assert parse_dsn("postgresql://someone@example.com/somedb?connect_timeout=10") == { - "host": "example.com", - "user": "someone", - "dbname": "somedb", - "connect_timeout": "10", - } - - for name in connections: - cursor = connections[name].cursor() - cursor.execute("SELECT 1;") - assert cursor.fetchone() is not None - - # test decorators @@ -969,37 +832,6 @@ def signup_view(request: HttpRequest) -> HttpResponse: # type: ignore[empty-bod ... -def test_psycopg_top_level_exports() -> None: - psycopg2.BINARY - psycopg2.Binary - psycopg2.DATETIME - psycopg2.DataError - psycopg2.DatabaseError - psycopg2.Date - psycopg2.DateFromTicks - psycopg2.Error - psycopg2.IntegrityError - psycopg2.InterfaceError - psycopg2.InternalError - psycopg2.NUMBER - psycopg2.NotSupportedError - psycopg2.OperationalError - psycopg2.ProgrammingError - psycopg2.ROWID - psycopg2.STRING - psycopg2.Time - psycopg2.TimeFromTicks - psycopg2.Timestamp - psycopg2.TimestampFromTicks - psycopg2.Warning - psycopg2.connect - psycopg2.errors - psycopg2.extensions - psycopg2.paramstyle - psycopg2.threadsafety - psycopg2.tz - - def namedtuplefetchall(cursor: CursorWrapper) -> List[Tuple[Any, ...]]: "Return all rows from a cursor as a namedtuple" desc = cursor.description diff --git a/typings/psycopg2 b/typings/psycopg2 deleted file mode 120000 index 927638bd3..000000000 --- a/typings/psycopg2 +++ /dev/null @@ -1 +0,0 @@ -../psycopg2-stubs \ No newline at end of file