From 40361687fcc9a62741153dc77c6e0fdb53d73ace Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Fri, 26 Jan 2024 12:18:58 +0000 Subject: [PATCH] chore: bump black to 24.1.0 --- .flake8 | 2 +- psycopg/.flake8 | 2 +- psycopg/psycopg/_struct.py | 3 +- psycopg/psycopg/_typeinfo.py | 18 +- psycopg/psycopg/abc.py | 59 ++--- psycopg/psycopg/adapt.py | 3 +- psycopg/psycopg/connection.py | 15 +- psycopg/psycopg/connection_async.py | 15 +- psycopg/psycopg/copy.py | 15 +- psycopg/psycopg/crdb/connection.py | 12 +- psycopg/psycopg/cursor.py | 8 +- psycopg/psycopg/cursor_async.py | 6 +- psycopg/psycopg/pq/abc.py | 279 ++++++++---------------- psycopg/psycopg/rows.py | 12 +- psycopg/psycopg/server_cursor.py | 12 +- psycopg/psycopg/types/enum.py | 1 + psycopg/psycopg/types/multirange.py | 12 +- psycopg/setup.py | 2 +- psycopg_c/.flake8 | 2 +- psycopg_pool/.flake8 | 2 +- psycopg_pool/psycopg_pool/pool.py | 3 +- psycopg_pool/psycopg_pool/pool_async.py | 3 +- tests/constraints.txt | 2 +- tests/scripts/dectest.py | 1 + tests/scripts/pipeline-demo.py | 1 + tests/test_connection_async.py | 2 +- tests/types/test_numeric.py | 8 +- 27 files changed, 176 insertions(+), 324 deletions(-) diff --git a/.flake8 b/.flake8 index ec4053fb2..d2473a1ae 100644 --- a/.flake8 +++ b/.flake8 @@ -1,6 +1,6 @@ [flake8] max-line-length = 88 -ignore = W503, E203 +ignore = W503, E203, E704 extend-exclude = .venv build per-file-ignores = # Autogenerated section diff --git a/psycopg/.flake8 b/psycopg/.flake8 index 67fb0245c..33b08d768 100644 --- a/psycopg/.flake8 +++ b/psycopg/.flake8 @@ -1,6 +1,6 @@ [flake8] max-line-length = 88 -ignore = W503, E203 +ignore = W503, E203, E704 per-file-ignores = # Autogenerated section psycopg/errors.py: E125, E128, E302 diff --git a/psycopg/psycopg/_struct.py b/psycopg/psycopg/_struct.py index 28a608447..57d1e3eff 100644 --- a/psycopg/psycopg/_struct.py +++ b/psycopg/psycopg/_struct.py @@ -19,8 +19,7 @@ UnpackFloat: TypeAlias = Callable[[Buffer], Tuple[float]] class UnpackLen(Protocol): - def __call__(self, data: Buffer, start: Optional[int]) -> Tuple[int]: - ... + def __call__(self, data: Buffer, start: Optional[int]) -> Tuple[int]: ... pack_int2 = cast(PackInt, struct.Struct("!h").pack) diff --git a/psycopg/psycopg/_typeinfo.py b/psycopg/psycopg/_typeinfo.py index 08c5e650c..ab6f1f1a6 100644 --- a/psycopg/psycopg/_typeinfo.py +++ b/psycopg/psycopg/_typeinfo.py @@ -57,15 +57,13 @@ class TypeInfo: @classmethod def fetch( cls: Type[T], conn: "Connection[Any]", name: Union[str, "Identifier"] - ) -> Optional[T]: - ... + ) -> Optional[T]: ... @overload @classmethod async def fetch( cls: Type[T], conn: "AsyncConnection[Any]", name: Union[str, "Identifier"] - ) -> Optional[T]: - ... + ) -> Optional[T]: ... @classmethod def fetch( @@ -414,12 +412,10 @@ class TypesRegistry: yield t @overload - def __getitem__(self, key: Union[str, int]) -> TypeInfo: - ... + def __getitem__(self, key: Union[str, int]) -> TypeInfo: ... @overload - def __getitem__(self, key: Tuple[Type[T], int]) -> T: - ... + def __getitem__(self, key: Tuple[Type[T], int]) -> T: ... def __getitem__(self, key: RegistryKey) -> TypeInfo: """ @@ -440,12 +436,10 @@ class TypesRegistry: raise KeyError(f"couldn't find the type {key!r} in the types registry") @overload - def get(self, key: Union[str, int]) -> Optional[TypeInfo]: - ... + def get(self, key: Union[str, int]) -> Optional[TypeInfo]: ... @overload - def get(self, key: Tuple[Type[T], int]) -> Optional[T]: - ... + def get(self, key: Tuple[Type[T], int]) -> Optional[T]: ... def get(self, key: RegistryKey) -> Optional[TypeInfo]: """ diff --git a/psycopg/psycopg/abc.py b/psycopg/psycopg/abc.py index 0cf1a7511..22979906b 100644 --- a/psycopg/psycopg/abc.py +++ b/psycopg/psycopg/abc.py @@ -54,8 +54,7 @@ class WaitFunc(Protocol): def __call__( self, gen: PQGen[RV], fileno: int, timeout: Optional[float] = None - ) -> RV: - ... + ) -> RV: ... # Adaptation types @@ -106,8 +105,7 @@ class Dumper(Protocol): oid: int """The oid to pass to the server, if known; 0 otherwise (class attribute).""" - def __init__(self, cls: type, context: Optional[AdaptContext] = None): - ... + def __init__(self, cls: type, context: Optional[AdaptContext] = None): ... def dump(self, obj: Any) -> Buffer: """Convert the object `!obj` to PostgreSQL representation. @@ -187,8 +185,7 @@ class Loader(Protocol): This is a class attribute. """ - def __init__(self, oid: int, context: Optional[AdaptContext] = None): - ... + def __init__(self, oid: int, context: Optional[AdaptContext] = None): ... def load(self, data: Buffer) -> Any: """ @@ -203,28 +200,22 @@ class Transformer(Protocol): types: Optional[Tuple[int, ...]] formats: Optional[List[pq.Format]] - def __init__(self, context: Optional[AdaptContext] = None): - ... + def __init__(self, context: Optional[AdaptContext] = None): ... @classmethod - def from_context(cls, context: Optional[AdaptContext]) -> "Transformer": - ... + def from_context(cls, context: Optional[AdaptContext]) -> "Transformer": ... @property - def connection(self) -> Optional["BaseConnection[Any]"]: - ... + def connection(self) -> Optional["BaseConnection[Any]"]: ... @property - def encoding(self) -> str: - ... + def encoding(self) -> str: ... @property - def adapters(self) -> "AdaptersMap": - ... + def adapters(self) -> "AdaptersMap": ... @property - def pgresult(self) -> Optional["PGresult"]: - ... + def pgresult(self) -> Optional["PGresult"]: ... def set_pgresult( self, @@ -232,34 +223,26 @@ class Transformer(Protocol): *, set_loaders: bool = True, format: Optional[pq.Format] = None - ) -> None: - ... + ) -> None: ... - def set_dumper_types(self, types: Sequence[int], format: pq.Format) -> None: - ... + def set_dumper_types(self, types: Sequence[int], format: pq.Format) -> None: ... - def set_loader_types(self, types: Sequence[int], format: pq.Format) -> None: - ... + def set_loader_types(self, types: Sequence[int], format: pq.Format) -> None: ... def dump_sequence( self, params: Sequence[Any], formats: Sequence[PyFormat] - ) -> Sequence[Optional[Buffer]]: - ... + ) -> Sequence[Optional[Buffer]]: ... - def as_literal(self, obj: Any) -> bytes: - ... + def as_literal(self, obj: Any) -> bytes: ... - def get_dumper(self, obj: Any, format: PyFormat) -> Dumper: - ... + def get_dumper(self, obj: Any, format: PyFormat) -> Dumper: ... - def load_rows(self, row0: int, row1: int, make_row: "RowMaker[Row]") -> List["Row"]: - ... + def load_rows( + self, row0: int, row1: int, make_row: "RowMaker[Row]" + ) -> List["Row"]: ... - def load_row(self, row: int, make_row: "RowMaker[Row]") -> Optional["Row"]: - ... + def load_row(self, row: int, make_row: "RowMaker[Row]") -> Optional["Row"]: ... - def load_sequence(self, record: Sequence[Optional[Buffer]]) -> Tuple[Any, ...]: - ... + def load_sequence(self, record: Sequence[Optional[Buffer]]) -> Tuple[Any, ...]: ... - def get_loader(self, oid: int, format: pq.Format) -> Loader: - ... + def get_loader(self, oid: int, format: pq.Format) -> Loader: ... diff --git a/psycopg/psycopg/adapt.py b/psycopg/psycopg/adapt.py index 7ec4a5597..738e49f3a 100644 --- a/psycopg/psycopg/adapt.py +++ b/psycopg/psycopg/adapt.py @@ -45,8 +45,7 @@ class Dumper(abc.Dumper, ABC): ) @abstractmethod - def dump(self, obj: Any) -> Buffer: - ... + def dump(self, obj: Any) -> Buffer: ... def quote(self, obj: Any) -> Buffer: """ diff --git a/psycopg/psycopg/connection.py b/psycopg/psycopg/connection.py index 560945b00..e866368ac 100644 --- a/psycopg/psycopg/connection.py +++ b/psycopg/psycopg/connection.py @@ -705,8 +705,7 @@ class Connection(BaseConnection[Row]): cursor_factory: Optional[Type[Cursor[Any]]] = None, context: Optional[AdaptContext] = None, **kwargs: Union[None, int, str], - ) -> "Connection[TupleRow]": - ... + ) -> "Connection[TupleRow]": ... @classmethod # type: ignore[misc] # https://github.com/python/mypy/issues/11004 def connect( @@ -810,14 +809,12 @@ class Connection(BaseConnection[Row]): self.pgconn.finish() @overload - def cursor(self, *, binary: bool = False) -> Cursor[Row]: - ... + def cursor(self, *, binary: bool = False) -> Cursor[Row]: ... @overload def cursor( self, *, binary: bool = False, row_factory: RowFactory[CursorRow] - ) -> Cursor[CursorRow]: - ... + ) -> Cursor[CursorRow]: ... @overload def cursor( @@ -827,8 +824,7 @@ class Connection(BaseConnection[Row]): binary: bool = False, scrollable: Optional[bool] = None, withhold: bool = False, - ) -> ServerCursor[Row]: - ... + ) -> ServerCursor[Row]: ... @overload def cursor( @@ -839,8 +835,7 @@ class Connection(BaseConnection[Row]): row_factory: RowFactory[CursorRow], scrollable: Optional[bool] = None, withhold: bool = False, - ) -> ServerCursor[CursorRow]: - ... + ) -> ServerCursor[CursorRow]: ... def cursor( self, diff --git a/psycopg/psycopg/connection_async.py b/psycopg/psycopg/connection_async.py index 0422159e5..995372a82 100644 --- a/psycopg/psycopg/connection_async.py +++ b/psycopg/psycopg/connection_async.py @@ -95,8 +95,7 @@ class AsyncConnection(BaseConnection[Row]): cursor_factory: Optional[Type[AsyncCursor[Any]]] = None, context: Optional[AdaptContext] = None, **kwargs: Union[None, int, str], - ) -> "AsyncConnection[TupleRow]": - ... + ) -> "AsyncConnection[TupleRow]": ... @classmethod # type: ignore[misc] # https://github.com/python/mypy/issues/11004 async def connect( @@ -200,14 +199,12 @@ class AsyncConnection(BaseConnection[Row]): self.pgconn.finish() @overload - def cursor(self, *, binary: bool = False) -> AsyncCursor[Row]: - ... + def cursor(self, *, binary: bool = False) -> AsyncCursor[Row]: ... @overload def cursor( self, *, binary: bool = False, row_factory: AsyncRowFactory[CursorRow] - ) -> AsyncCursor[CursorRow]: - ... + ) -> AsyncCursor[CursorRow]: ... @overload def cursor( @@ -217,8 +214,7 @@ class AsyncConnection(BaseConnection[Row]): binary: bool = False, scrollable: Optional[bool] = None, withhold: bool = False, - ) -> AsyncServerCursor[Row]: - ... + ) -> AsyncServerCursor[Row]: ... @overload def cursor( @@ -229,8 +225,7 @@ class AsyncConnection(BaseConnection[Row]): row_factory: AsyncRowFactory[CursorRow], scrollable: Optional[bool] = None, withhold: bool = False, - ) -> AsyncServerCursor[CursorRow]: - ... + ) -> AsyncServerCursor[CursorRow]: ... def cursor( self, diff --git a/psycopg/psycopg/copy.py b/psycopg/psycopg/copy.py index 7b41b288b..f20c86a24 100644 --- a/psycopg/psycopg/copy.py +++ b/psycopg/psycopg/copy.py @@ -552,8 +552,7 @@ class AsyncWriter(ABC): """ @abstractmethod - async def write(self, data: Buffer) -> None: - ... + async def write(self, data: Buffer) -> None: ... async def finish(self, exc: Optional[BaseException] = None) -> None: pass @@ -667,20 +666,16 @@ class Formatter(ABC): self._row_mode = False # true if the user is using write_row() @abstractmethod - def parse_row(self, data: Buffer) -> Optional[Tuple[Any, ...]]: - ... + def parse_row(self, data: Buffer) -> Optional[Tuple[Any, ...]]: ... @abstractmethod - def write(self, buffer: Union[Buffer, str]) -> Buffer: - ... + def write(self, buffer: Union[Buffer, str]) -> Buffer: ... @abstractmethod - def write_row(self, row: Sequence[Any]) -> Buffer: - ... + def write_row(self, row: Sequence[Any]) -> Buffer: ... @abstractmethod - def end(self) -> Buffer: - ... + def end(self) -> Buffer: ... class TextFormatter(Formatter): diff --git a/psycopg/psycopg/crdb/connection.py b/psycopg/psycopg/crdb/connection.py index 07c3837dc..53c827b87 100644 --- a/psycopg/psycopg/crdb/connection.py +++ b/psycopg/psycopg/crdb/connection.py @@ -78,8 +78,7 @@ class CrdbConnection(_CrdbConnectionMixin, Connection[Row]): cursor_factory: "Optional[Type[Cursor[Row]]]" = None, context: Optional[AdaptContext] = None, **kwargs: Union[None, int, str], - ) -> "CrdbConnection[Row]": - ... + ) -> "CrdbConnection[Row]": ... @overload @classmethod @@ -92,8 +91,7 @@ class CrdbConnection(_CrdbConnectionMixin, Connection[Row]): cursor_factory: "Optional[Type[Cursor[Any]]]" = None, context: Optional[AdaptContext] = None, **kwargs: Union[None, int, str], - ) -> "CrdbConnection[TupleRow]": - ... + ) -> "CrdbConnection[TupleRow]": ... @classmethod def connect(cls, conninfo: str = "", **kwargs: Any) -> Self: @@ -125,8 +123,7 @@ class AsyncCrdbConnection(_CrdbConnectionMixin, AsyncConnection[Row]): cursor_factory: "Optional[Type[AsyncCursor[Row]]]" = None, context: Optional[AdaptContext] = None, **kwargs: Union[None, int, str], - ) -> "AsyncCrdbConnection[Row]": - ... + ) -> "AsyncCrdbConnection[Row]": ... @overload @classmethod @@ -139,8 +136,7 @@ class AsyncCrdbConnection(_CrdbConnectionMixin, AsyncConnection[Row]): cursor_factory: "Optional[Type[AsyncCursor[Any]]]" = None, context: Optional[AdaptContext] = None, **kwargs: Union[None, int, str], - ) -> "AsyncCrdbConnection[TupleRow]": - ... + ) -> "AsyncCrdbConnection[TupleRow]": ... @classmethod async def connect(cls, conninfo: str = "", **kwargs: Any) -> Self: diff --git a/psycopg/psycopg/cursor.py b/psycopg/psycopg/cursor.py index a54cb2022..e2893762e 100644 --- a/psycopg/psycopg/cursor.py +++ b/psycopg/psycopg/cursor.py @@ -665,12 +665,12 @@ class Cursor(BaseCursor["Connection[Any]", Row]): __slots__ = () @overload - def __init__(self, connection: "Connection[Row]"): - ... + def __init__(self, connection: "Connection[Row]"): ... @overload - def __init__(self, connection: "Connection[Any]", *, row_factory: RowFactory[Row]): - ... + def __init__( + self, connection: "Connection[Any]", *, row_factory: RowFactory[Row] + ): ... def __init__( self, diff --git a/psycopg/psycopg/cursor_async.py b/psycopg/psycopg/cursor_async.py index 012e281bd..412447337 100644 --- a/psycopg/psycopg/cursor_async.py +++ b/psycopg/psycopg/cursor_async.py @@ -29,14 +29,12 @@ class AsyncCursor(BaseCursor["AsyncConnection[Any]", Row]): __slots__ = () @overload - def __init__(self, connection: "AsyncConnection[Row]"): - ... + def __init__(self, connection: "AsyncConnection[Row]"): ... @overload def __init__( self, connection: "AsyncConnection[Any]", *, row_factory: AsyncRowFactory[Row] - ): - ... + ): ... def __init__( self, diff --git a/psycopg/psycopg/pq/abc.py b/psycopg/psycopg/pq/abc.py index 971d00eea..1b475f7dc 100644 --- a/psycopg/psycopg/pq/abc.py +++ b/psycopg/psycopg/pq/abc.py @@ -23,112 +23,83 @@ class PGconn(Protocol): notify_handler: Optional[Callable[["PGnotify"], None]] @classmethod - def connect(cls, conninfo: bytes) -> "PGconn": - ... + def connect(cls, conninfo: bytes) -> "PGconn": ... @classmethod - def connect_start(cls, conninfo: bytes) -> "PGconn": - ... + def connect_start(cls, conninfo: bytes) -> "PGconn": ... - def connect_poll(self) -> int: - ... + def connect_poll(self) -> int: ... - def finish(self) -> None: - ... + def finish(self) -> None: ... @property - def info(self) -> List["ConninfoOption"]: - ... + def info(self) -> List["ConninfoOption"]: ... - def reset(self) -> None: - ... + def reset(self) -> None: ... - def reset_start(self) -> None: - ... + def reset_start(self) -> None: ... - def reset_poll(self) -> int: - ... + def reset_poll(self) -> int: ... @classmethod - def ping(self, conninfo: bytes) -> int: - ... + def ping(self, conninfo: bytes) -> int: ... @property - def db(self) -> bytes: - ... + def db(self) -> bytes: ... @property - def user(self) -> bytes: - ... + def user(self) -> bytes: ... @property - def password(self) -> bytes: - ... + def password(self) -> bytes: ... @property - def host(self) -> bytes: - ... + def host(self) -> bytes: ... @property - def hostaddr(self) -> bytes: - ... + def hostaddr(self) -> bytes: ... @property - def port(self) -> bytes: - ... + def port(self) -> bytes: ... @property - def tty(self) -> bytes: - ... + def tty(self) -> bytes: ... @property - def options(self) -> bytes: - ... + def options(self) -> bytes: ... @property - def status(self) -> int: - ... + def status(self) -> int: ... @property - def transaction_status(self) -> int: - ... + def transaction_status(self) -> int: ... - def parameter_status(self, name: bytes) -> Optional[bytes]: - ... + def parameter_status(self, name: bytes) -> Optional[bytes]: ... @property - def error_message(self) -> bytes: - ... + def error_message(self) -> bytes: ... @property - def server_version(self) -> int: - ... + def server_version(self) -> int: ... @property - def socket(self) -> int: - ... + def socket(self) -> int: ... @property - def backend_pid(self) -> int: - ... + def backend_pid(self) -> int: ... @property - def needs_password(self) -> bool: - ... + def needs_password(self) -> bool: ... @property - def used_password(self) -> bool: - ... + def used_password(self) -> bool: ... @property - def ssl_in_use(self) -> bool: - ... + def ssl_in_use(self) -> bool: ... - def exec_(self, command: bytes) -> "PGresult": - ... + def exec_(self, command: bytes) -> "PGresult": ... - def send_query(self, command: bytes) -> None: - ... + def send_query(self, command: bytes) -> None: ... def exec_params( self, @@ -137,8 +108,7 @@ class PGconn(Protocol): param_types: Optional[Sequence[int]] = None, param_formats: Optional[Sequence[int]] = None, result_format: int = Format.TEXT, - ) -> "PGresult": - ... + ) -> "PGresult": ... def send_query_params( self, @@ -147,16 +117,14 @@ class PGconn(Protocol): param_types: Optional[Sequence[int]] = None, param_formats: Optional[Sequence[int]] = None, result_format: int = Format.TEXT, - ) -> None: - ... + ) -> None: ... def send_prepare( self, name: bytes, command: bytes, param_types: Optional[Sequence[int]] = None, - ) -> None: - ... + ) -> None: ... def send_query_prepared( self, @@ -164,16 +132,14 @@ class PGconn(Protocol): param_values: Optional[Sequence[Optional[Buffer]]], param_formats: Optional[Sequence[int]] = None, result_format: int = Format.TEXT, - ) -> None: - ... + ) -> None: ... def prepare( self, name: bytes, command: bytes, param_types: Optional[Sequence[int]] = None, - ) -> "PGresult": - ... + ) -> "PGresult": ... def exec_prepared( self, @@ -181,204 +147,145 @@ class PGconn(Protocol): param_values: Optional[Sequence[Buffer]], param_formats: Optional[Sequence[int]] = None, result_format: int = 0, - ) -> "PGresult": - ... + ) -> "PGresult": ... - def describe_prepared(self, name: bytes) -> "PGresult": - ... + def describe_prepared(self, name: bytes) -> "PGresult": ... - def send_describe_prepared(self, name: bytes) -> None: - ... + def send_describe_prepared(self, name: bytes) -> None: ... - def describe_portal(self, name: bytes) -> "PGresult": - ... + def describe_portal(self, name: bytes) -> "PGresult": ... - def send_describe_portal(self, name: bytes) -> None: - ... + def send_describe_portal(self, name: bytes) -> None: ... - def get_result(self) -> Optional["PGresult"]: - ... + def get_result(self) -> Optional["PGresult"]: ... - def consume_input(self) -> None: - ... + def consume_input(self) -> None: ... - def is_busy(self) -> int: - ... + def is_busy(self) -> int: ... @property - def nonblocking(self) -> int: - ... + def nonblocking(self) -> int: ... @nonblocking.setter - def nonblocking(self, arg: int) -> None: - ... + def nonblocking(self, arg: int) -> None: ... - def flush(self) -> int: - ... + def flush(self) -> int: ... - def set_single_row_mode(self) -> None: - ... + def set_single_row_mode(self) -> None: ... - def get_cancel(self) -> "PGcancel": - ... + def get_cancel(self) -> "PGcancel": ... - def notifies(self) -> Optional["PGnotify"]: - ... + def notifies(self) -> Optional["PGnotify"]: ... - def put_copy_data(self, buffer: Buffer) -> int: - ... + def put_copy_data(self, buffer: Buffer) -> int: ... - def put_copy_end(self, error: Optional[bytes] = None) -> int: - ... + def put_copy_end(self, error: Optional[bytes] = None) -> int: ... - def get_copy_data(self, async_: int) -> Tuple[int, memoryview]: - ... + def get_copy_data(self, async_: int) -> Tuple[int, memoryview]: ... - def trace(self, fileno: int) -> None: - ... + def trace(self, fileno: int) -> None: ... - def set_trace_flags(self, flags: Trace) -> None: - ... + def set_trace_flags(self, flags: Trace) -> None: ... - def untrace(self) -> None: - ... + def untrace(self) -> None: ... def encrypt_password( self, passwd: bytes, user: bytes, algorithm: Optional[bytes] = None - ) -> bytes: - ... + ) -> bytes: ... - def make_empty_result(self, exec_status: int) -> "PGresult": - ... + def make_empty_result(self, exec_status: int) -> "PGresult": ... @property - def pipeline_status(self) -> int: - ... + def pipeline_status(self) -> int: ... - def enter_pipeline_mode(self) -> None: - ... + def enter_pipeline_mode(self) -> None: ... - def exit_pipeline_mode(self) -> None: - ... + def exit_pipeline_mode(self) -> None: ... - def pipeline_sync(self) -> None: - ... + def pipeline_sync(self) -> None: ... - def send_flush_request(self) -> None: - ... + def send_flush_request(self) -> None: ... class PGresult(Protocol): - def clear(self) -> None: - ... + def clear(self) -> None: ... @property - def status(self) -> int: - ... + def status(self) -> int: ... @property - def error_message(self) -> bytes: - ... + def error_message(self) -> bytes: ... - def error_field(self, fieldcode: int) -> Optional[bytes]: - ... + def error_field(self, fieldcode: int) -> Optional[bytes]: ... @property - def ntuples(self) -> int: - ... + def ntuples(self) -> int: ... @property - def nfields(self) -> int: - ... + def nfields(self) -> int: ... - def fname(self, column_number: int) -> Optional[bytes]: - ... + def fname(self, column_number: int) -> Optional[bytes]: ... - def ftable(self, column_number: int) -> int: - ... + def ftable(self, column_number: int) -> int: ... - def ftablecol(self, column_number: int) -> int: - ... + def ftablecol(self, column_number: int) -> int: ... - def fformat(self, column_number: int) -> int: - ... + def fformat(self, column_number: int) -> int: ... - def ftype(self, column_number: int) -> int: - ... + def ftype(self, column_number: int) -> int: ... - def fmod(self, column_number: int) -> int: - ... + def fmod(self, column_number: int) -> int: ... - def fsize(self, column_number: int) -> int: - ... + def fsize(self, column_number: int) -> int: ... @property - def binary_tuples(self) -> int: - ... + def binary_tuples(self) -> int: ... - def get_value(self, row_number: int, column_number: int) -> Optional[bytes]: - ... + def get_value(self, row_number: int, column_number: int) -> Optional[bytes]: ... @property - def nparams(self) -> int: - ... + def nparams(self) -> int: ... - def param_type(self, param_number: int) -> int: - ... + def param_type(self, param_number: int) -> int: ... @property - def command_status(self) -> Optional[bytes]: - ... + def command_status(self) -> Optional[bytes]: ... @property - def command_tuples(self) -> Optional[int]: - ... + def command_tuples(self) -> Optional[int]: ... @property - def oid_value(self) -> int: - ... + def oid_value(self) -> int: ... - def set_attributes(self, descriptions: List["PGresAttDesc"]) -> None: - ... + def set_attributes(self, descriptions: List["PGresAttDesc"]) -> None: ... class PGcancel(Protocol): - def free(self) -> None: - ... + def free(self) -> None: ... - def cancel(self) -> None: - ... + def cancel(self) -> None: ... class Conninfo(Protocol): @classmethod - def get_defaults(cls) -> List["ConninfoOption"]: - ... + def get_defaults(cls) -> List["ConninfoOption"]: ... @classmethod - def parse(cls, conninfo: bytes) -> List["ConninfoOption"]: - ... + def parse(cls, conninfo: bytes) -> List["ConninfoOption"]: ... @classmethod - def _options_from_array(cls, opts: Sequence[Any]) -> List["ConninfoOption"]: - ... + def _options_from_array(cls, opts: Sequence[Any]) -> List["ConninfoOption"]: ... class Escaping(Protocol): - def __init__(self, conn: Optional[PGconn] = None): - ... + def __init__(self, conn: Optional[PGconn] = None): ... - def escape_literal(self, data: Buffer) -> bytes: - ... + def escape_literal(self, data: Buffer) -> bytes: ... - def escape_identifier(self, data: Buffer) -> bytes: - ... + def escape_identifier(self, data: Buffer) -> bytes: ... - def escape_string(self, data: Buffer) -> bytes: - ... + def escape_string(self, data: Buffer) -> bytes: ... - def escape_bytea(self, data: Buffer) -> bytes: - ... + def escape_bytea(self, data: Buffer) -> bytes: ... - def unescape_bytea(self, data: Buffer) -> bytes: - ... + def unescape_bytea(self, data: Buffer) -> bytes: ... diff --git a/psycopg/psycopg/rows.py b/psycopg/psycopg/rows.py index 2b240f7fb..89fe2a1ab 100644 --- a/psycopg/psycopg/rows.py +++ b/psycopg/psycopg/rows.py @@ -43,8 +43,7 @@ class RowMaker(Protocol[Row]): Typically, `!RowMaker` functions are returned by `RowFactory`. """ - def __call__(self, __values: Sequence[Any]) -> Row: - ... + def __call__(self, __values: Sequence[Any]) -> Row: ... class RowFactory(Protocol[Row]): @@ -61,8 +60,7 @@ class RowFactory(Protocol[Row]): use the values to create a dictionary for each record. """ - def __call__(self, __cursor: "Cursor[Any]") -> RowMaker[Row]: - ... + def __call__(self, __cursor: "Cursor[Any]") -> RowMaker[Row]: ... class AsyncRowFactory(Protocol[Row]): @@ -70,8 +68,7 @@ class AsyncRowFactory(Protocol[Row]): Like `RowFactory`, taking an async cursor as argument. """ - def __call__(self, __cursor: "AsyncCursor[Any]") -> RowMaker[Row]: - ... + def __call__(self, __cursor: "AsyncCursor[Any]") -> RowMaker[Row]: ... class BaseRowFactory(Protocol[Row]): @@ -79,8 +76,7 @@ class BaseRowFactory(Protocol[Row]): Like `RowFactory`, taking either type of cursor as argument. """ - def __call__(self, __cursor: "BaseCursor[Any, Any]") -> RowMaker[Row]: - ... + def __call__(self, __cursor: "BaseCursor[Any, Any]") -> RowMaker[Row]: ... TupleRow: TypeAlias = Tuple[Any, ...] diff --git a/psycopg/psycopg/server_cursor.py b/psycopg/psycopg/server_cursor.py index d2f4ab14a..77d78f74a 100644 --- a/psycopg/psycopg/server_cursor.py +++ b/psycopg/psycopg/server_cursor.py @@ -221,8 +221,7 @@ class ServerCursor(ServerCursorMixin["Connection[Any]", Row], Cursor[Row]): *, scrollable: Optional[bool] = None, withhold: bool = False, - ): - ... + ): ... @overload def __init__( @@ -233,8 +232,7 @@ class ServerCursor(ServerCursorMixin["Connection[Any]", Row], Cursor[Row]): row_factory: RowFactory[Row], scrollable: Optional[bool] = None, withhold: bool = False, - ): - ... + ): ... def __init__( self, @@ -362,8 +360,7 @@ class AsyncServerCursor( *, scrollable: Optional[bool] = None, withhold: bool = False, - ): - ... + ): ... @overload def __init__( @@ -374,8 +371,7 @@ class AsyncServerCursor( row_factory: AsyncRowFactory[Row], scrollable: Optional[bool] = None, withhold: bool = False, - ): - ... + ): ... def __init__( self, diff --git a/psycopg/psycopg/types/enum.py b/psycopg/psycopg/types/enum.py index 96a81bf4e..0e79f92ff 100644 --- a/psycopg/psycopg/types/enum.py +++ b/psycopg/psycopg/types/enum.py @@ -1,6 +1,7 @@ """ Adapters for the enum type. """ + from enum import Enum from typing import Dict, Generic, Optional, Mapping, Sequence from typing import Tuple, Type, TypeVar, Union, cast diff --git a/psycopg/psycopg/types/multirange.py b/psycopg/psycopg/types/multirange.py index 360f49e6d..548ced9c7 100644 --- a/psycopg/psycopg/types/multirange.py +++ b/psycopg/psycopg/types/multirange.py @@ -46,12 +46,10 @@ class Multirange(MutableSequence[Range[T]]): return f"{{{', '.join(map(str, self._ranges))}}}" @overload - def __getitem__(self, index: int) -> Range[T]: - ... + def __getitem__(self, index: int) -> Range[T]: ... @overload - def __getitem__(self, index: slice) -> "Multirange[T]": - ... + def __getitem__(self, index: slice) -> "Multirange[T]": ... def __getitem__(self, index: Union[int, slice]) -> "Union[Range[T],Multirange[T]]": if isinstance(index, int): @@ -63,12 +61,10 @@ class Multirange(MutableSequence[Range[T]]): return len(self._ranges) @overload - def __setitem__(self, index: int, value: Range[T]) -> None: - ... + def __setitem__(self, index: int, value: Range[T]) -> None: ... @overload - def __setitem__(self, index: slice, value: Iterable[Range[T]]) -> None: - ... + def __setitem__(self, index: slice, value: Iterable[Range[T]]) -> None: ... def __setitem__( self, diff --git a/psycopg/setup.py b/psycopg/setup.py index a1143a6c4..ac2f755c7 100644 --- a/psycopg/setup.py +++ b/psycopg/setup.py @@ -46,7 +46,7 @@ extras_require = { ], # Requirements needed for development "dev": [ - "black >= 23.1.0", + "black >= 24.1.0", "codespell >= 2.2", "dnspython >= 2.1", "flake8 >= 4.0", diff --git a/psycopg_c/.flake8 b/psycopg_c/.flake8 index 2ae629c2d..40a061b1e 100644 --- a/psycopg_c/.flake8 +++ b/psycopg_c/.flake8 @@ -1,3 +1,3 @@ [flake8] max-line-length = 88 -ignore = W503, E203 +ignore = W503, E203, E704 diff --git a/psycopg_pool/.flake8 b/psycopg_pool/.flake8 index 2ae629c2d..40a061b1e 100644 --- a/psycopg_pool/.flake8 +++ b/psycopg_pool/.flake8 @@ -1,3 +1,3 @@ [flake8] max-line-length = 88 -ignore = W503, E203 +ignore = W503, E203, E704 diff --git a/psycopg_pool/psycopg_pool/pool.py b/psycopg_pool/psycopg_pool/pool.py index 6d0dcbab4..593920bae 100644 --- a/psycopg_pool/psycopg_pool/pool.py +++ b/psycopg_pool/psycopg_pool/pool.py @@ -826,8 +826,7 @@ class MaintenanceTask(ABC): pool.run_task(self) @abstractmethod - def _run(self, pool: "ConnectionPool") -> None: - ... + def _run(self, pool: "ConnectionPool") -> None: ... class StopWorker(MaintenanceTask): diff --git a/psycopg_pool/psycopg_pool/pool_async.py b/psycopg_pool/psycopg_pool/pool_async.py index 6454f47e6..6ff94b96d 100644 --- a/psycopg_pool/psycopg_pool/pool_async.py +++ b/psycopg_pool/psycopg_pool/pool_async.py @@ -756,8 +756,7 @@ class MaintenanceTask(ABC): pool.run_task(self) @abstractmethod - async def _run(self, pool: "AsyncConnectionPool") -> None: - ... + async def _run(self, pool: "AsyncConnectionPool") -> None: ... class StopWorker(MaintenanceTask): diff --git a/tests/constraints.txt b/tests/constraints.txt index a3f4c1907..a34fd47a1 100644 --- a/tests/constraints.txt +++ b/tests/constraints.txt @@ -17,7 +17,7 @@ pytest-cov == 3.0.0 pytest-randomly == 3.5.0 # From the 'dev' extra -black == 23.1.0 +black == 24.1.0 dnspython == 2.1.0 flake8 == 4.0.0 types-setuptools == 57.4.0 diff --git a/tests/scripts/dectest.py b/tests/scripts/dectest.py index a49f11685..0fb65ad90 100644 --- a/tests/scripts/dectest.py +++ b/tests/scripts/dectest.py @@ -1,6 +1,7 @@ """ A quick and rough performance comparison of text vs. binary Decimal adaptation """ + from random import randrange from decimal import Decimal import psycopg diff --git a/tests/scripts/pipeline-demo.py b/tests/scripts/pipeline-demo.py index ec952293a..74cc04d1f 100644 --- a/tests/scripts/pipeline-demo.py +++ b/tests/scripts/pipeline-demo.py @@ -7,6 +7,7 @@ We do not fetch results explicitly (using cursor.fetch*()), this is handled by execute() calls when pgconn socket is read-ready, which happens when the output buffer is full. """ + import argparse import asyncio import logging diff --git a/tests/test_connection_async.py b/tests/test_connection_async.py index 1cf040349..b8f1de5d6 100644 --- a/tests/test_connection_async.py +++ b/tests/test_connection_async.py @@ -606,7 +606,7 @@ async def test_cursor_factory(aconn): async with aconn.cursor() as cur: assert isinstance(cur, MyCursor) - async with (await aconn.execute("select 1")) as cur: + async with await aconn.execute("select 1") as cur: assert isinstance(cur, MyCursor) diff --git a/tests/types/test_numeric.py b/tests/types/test_numeric.py index fffc32f31..8e5db7668 100644 --- a/tests/types/test_numeric.py +++ b/tests/types/test_numeric.py @@ -402,9 +402,11 @@ def test_dump_numeric_binary(conn, expr): @pytest.mark.parametrize( "fmt_in", [ - f - if f != PyFormat.BINARY - else pytest.param(f, marks=pytest.mark.crdb_skip("binary decimal")) + ( + f + if f != PyFormat.BINARY + else pytest.param(f, marks=pytest.mark.crdb_skip("binary decimal")) + ) for f in PyFormat ], ) -- 2.47.2