From: Daniele Varrazzo Date: Wed, 1 Feb 2023 10:25:26 +0000 (+0100) Subject: chore: upgrade black to 23.1.0 X-Git-Tag: pool-3.2.0~128 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0d2ea7648336712988206ac1dac28f01be775413;p=thirdparty%2Fpsycopg.git chore: upgrade black to 23.1.0 Code reformatted to adhere to the new style requested (stricter on redundant tuples unpacking brackets and blank lines at blocks start). --- diff --git a/psycopg/psycopg/_column.py b/psycopg/psycopg/_column.py index 9e4e7357c..50577e637 100644 --- a/psycopg/psycopg/_column.py +++ b/psycopg/psycopg/_column.py @@ -18,7 +18,6 @@ class ColumnData(NamedTuple): class Column(Sequence[Any]): - __module__ = "psycopg" def __init__(self, cursor: "BaseCursor[Any, Any]", index: int): diff --git a/psycopg/psycopg/_pipeline.py b/psycopg/psycopg/_pipeline.py index c818d86e8..233d66b23 100644 --- a/psycopg/psycopg/_pipeline.py +++ b/psycopg/psycopg/_pipeline.py @@ -38,7 +38,6 @@ logger = logging.getLogger("psycopg") class BasePipeline: - command_queue: Deque[PipelineCommand] result_queue: Deque[PendingResult] _is_supported: Optional[bool] = None diff --git a/psycopg/psycopg/abc.py b/psycopg/psycopg/abc.py index 80c8fbfb3..0cf1a7511 100644 --- a/psycopg/psycopg/abc.py +++ b/psycopg/psycopg/abc.py @@ -200,7 +200,6 @@ class Loader(Protocol): class Transformer(Protocol): - types: Optional[Tuple[int, ...]] formats: Optional[List[pq.Format]] diff --git a/psycopg/psycopg/connection_async.py b/psycopg/psycopg/connection_async.py index aa02dc0d3..6d95d7641 100644 --- a/psycopg/psycopg/connection_async.py +++ b/psycopg/psycopg/connection_async.py @@ -107,7 +107,6 @@ class AsyncConnection(BaseConnection[Row]): cursor_factory: Optional[Type[AsyncCursor[Row]]] = None, **kwargs: Any, ) -> "AsyncConnection[Any]": - if sys.platform == "win32": loop = asyncio.get_running_loop() if isinstance(loop, asyncio.ProactorEventLoop): diff --git a/psycopg/psycopg/copy.py b/psycopg/psycopg/copy.py index 751430664..33322aa61 100644 --- a/psycopg/psycopg/copy.py +++ b/psycopg/psycopg/copy.py @@ -669,7 +669,6 @@ class Formatter(ABC): class TextFormatter(Formatter): - format = TEXT def __init__(self, transformer: Transformer, encoding: str = "utf-8"): @@ -714,7 +713,6 @@ class TextFormatter(Formatter): class BinaryFormatter(Formatter): - format = BINARY def __init__(self, transformer: Transformer): diff --git a/psycopg/psycopg/crdb/connection.py b/psycopg/psycopg/crdb/connection.py index 6e79ed1d0..451474b77 100644 --- a/psycopg/psycopg/crdb/connection.py +++ b/psycopg/psycopg/crdb/connection.py @@ -23,7 +23,6 @@ if TYPE_CHECKING: class _CrdbConnectionMixin: - _adapters: Optional[AdaptersMap] pgconn: "PGconn" diff --git a/psycopg/psycopg/cursor.py b/psycopg/psycopg/cursor.py index 7c32f29e4..8379c589a 100644 --- a/psycopg/psycopg/cursor.py +++ b/psycopg/psycopg/cursor.py @@ -771,7 +771,6 @@ class Cursor(BaseCursor["Connection[Any]", Row]): raise e.ProgrammingError("stream() cannot be used in pipeline mode") with self._conn.lock: - try: self._conn.wait(self._stream_send_gen(query, params, binary=binary)) first = True diff --git a/psycopg/psycopg/cursor_async.py b/psycopg/psycopg/cursor_async.py index 42cd8e501..405dc0064 100644 --- a/psycopg/psycopg/cursor_async.py +++ b/psycopg/psycopg/cursor_async.py @@ -135,7 +135,6 @@ class AsyncCursor(BaseCursor["AsyncConnection[Any]", Row]): raise e.ProgrammingError("stream() cannot be used in pipeline mode") async with self._conn.lock: - try: await self._conn.wait( self._stream_send_gen(query, params, binary=binary) diff --git a/psycopg/psycopg/postgres.py b/psycopg/psycopg/postgres.py index 7a5d9dd47..44565952d 100644 --- a/psycopg/psycopg/postgres.py +++ b/psycopg/psycopg/postgres.py @@ -16,7 +16,6 @@ adapters = AdaptersMap(types=types) def register_default_types(types: TypesRegistry) -> None: - from .types.range import RangeInfo from .types.multirange import MultirangeInfo @@ -106,7 +105,6 @@ def register_default_types(types: TypesRegistry) -> None: def register_default_adapters(context: AdaptContext) -> None: - from .types import array, bool, composite, datetime, enum, json, multirange from .types import net, none, numeric, range, string, uuid diff --git a/psycopg/psycopg/pq/_debug.py b/psycopg/psycopg/pq/_debug.py index f35d09f45..f86f3bdcb 100644 --- a/psycopg/psycopg/pq/_debug.py +++ b/psycopg/psycopg/pq/_debug.py @@ -91,7 +91,7 @@ def debugging(f: Func) -> Func: reprs = [] for arg in args: reprs.append(f"{arg!r}") - for (k, v) in kwargs.items(): + for k, v in kwargs.items(): reprs.append(f"{k}={v!r}") logger.info("PGconn.%s(%s)", f.__name__, ", ".join(reprs)) diff --git a/psycopg/psycopg/pq/abc.py b/psycopg/psycopg/pq/abc.py index 9c45f64d1..971d00eea 100644 --- a/psycopg/psycopg/pq/abc.py +++ b/psycopg/psycopg/pq/abc.py @@ -19,7 +19,6 @@ Buffer: TypeAlias = Union[bytes, bytearray, memoryview] class PGconn(Protocol): - notice_handler: Optional[Callable[["PGresult"], None]] notify_handler: Optional[Callable[["PGnotify"], None]] diff --git a/psycopg/psycopg/server_cursor.py b/psycopg/psycopg/server_cursor.py index b890d7728..31b7f2e67 100644 --- a/psycopg/psycopg/server_cursor.py +++ b/psycopg/psycopg/server_cursor.py @@ -188,7 +188,6 @@ class ServerCursorMixin(BaseCursor[ConnectionType, Row]): yield from self._conn._exec_command(query) def _make_declare_statement(self, query: Query) -> sql.Composed: - if isinstance(query, bytes): query = query.decode(self._encoding) if not isinstance(query, sql.Composable): diff --git a/psycopg/psycopg/types/array.py b/psycopg/psycopg/types/array.py index 93f9da389..af85be04c 100644 --- a/psycopg/psycopg/types/array.py +++ b/psycopg/psycopg/types/array.py @@ -110,7 +110,6 @@ class BaseListDumper(RecursiveDumper): class ListDumper(BaseListDumper): - delimiter = b"," def get_key(self, obj: List[Any], format: PyFormat) -> DumperKey: @@ -212,7 +211,6 @@ def _get_needs_quotes_regexp(delimiter: bytes) -> Pattern[bytes]: class ListBinaryDumper(BaseListDumper): - format = pq.Format.BINARY def get_key(self, obj: List[Any], format: PyFormat) -> DumperKey: @@ -292,7 +290,6 @@ class ListBinaryDumper(BaseListDumper): class ArrayLoader(RecursiveLoader): - delimiter = b"," base_oid: int @@ -302,7 +299,6 @@ class ArrayLoader(RecursiveLoader): class ArrayBinaryLoader(RecursiveLoader): - format = pq.Format.BINARY def load(self, data: Buffer) -> List[Any]: diff --git a/psycopg/psycopg/types/bool.py b/psycopg/psycopg/types/bool.py index db34ce17c..2ad53c2f4 100644 --- a/psycopg/psycopg/types/bool.py +++ b/psycopg/psycopg/types/bool.py @@ -11,7 +11,6 @@ from ..adapt import Buffer, Dumper, Loader class BoolDumper(Dumper): - oid = _oids.BOOL_OID def dump(self, obj: bool) -> bytes: @@ -22,7 +21,6 @@ class BoolDumper(Dumper): class BoolBinaryDumper(Dumper): - format = Format.BINARY oid = _oids.BOOL_OID @@ -36,7 +34,6 @@ class BoolLoader(Loader): class BoolBinaryLoader(Loader): - format = Format.BINARY def load(self, data: Buffer) -> bool: diff --git a/psycopg/psycopg/types/composite.py b/psycopg/psycopg/types/composite.py index 12059852e..e2a5d0d94 100644 --- a/psycopg/psycopg/types/composite.py +++ b/psycopg/psycopg/types/composite.py @@ -113,7 +113,6 @@ class SequenceDumper(RecursiveDumper): class TupleDumper(SequenceDumper): - # Should be this, but it doesn't work # oid = _oids.RECORD_OID @@ -122,7 +121,6 @@ class TupleDumper(SequenceDumper): class TupleBinaryDumper(RecursiveDumper): - format = pq.Format.BINARY # Subclasses must set an info @@ -234,7 +232,6 @@ class RecordBinaryLoader(Loader): class CompositeLoader(RecordLoader): - factory: Callable[..., Any] fields_types: List[int] _types_set = False @@ -256,7 +253,6 @@ class CompositeLoader(RecordLoader): class CompositeBinaryLoader(RecordBinaryLoader): - format = pq.Format.BINARY factory: Callable[..., Any] diff --git a/psycopg/psycopg/types/datetime.py b/psycopg/psycopg/types/datetime.py index d4842cdcd..f566f6dcf 100644 --- a/psycopg/psycopg/types/datetime.py +++ b/psycopg/psycopg/types/datetime.py @@ -38,7 +38,6 @@ _py_date_min_days = date.min.toordinal() class DateDumper(Dumper): - oid = _oids.DATE_OID def dump(self, obj: date) -> bytes: @@ -48,7 +47,6 @@ class DateDumper(Dumper): class DateBinaryDumper(Dumper): - format = Format.BINARY oid = _oids.DATE_OID @@ -76,7 +74,6 @@ class _BaseTimeTextDumper(_BaseTimeDumper): class TimeDumper(_BaseTimeTextDumper): - oid = _oids.TIME_OID def upgrade(self, obj: time, format: PyFormat) -> Dumper: @@ -87,12 +84,10 @@ class TimeDumper(_BaseTimeTextDumper): class TimeTzDumper(_BaseTimeTextDumper): - oid = _oids.TIMETZ_OID class TimeBinaryDumper(_BaseTimeDumper): - format = Format.BINARY oid = _oids.TIME_OID @@ -110,7 +105,6 @@ class TimeBinaryDumper(_BaseTimeDumper): class TimeTzBinaryDumper(_BaseTimeDumper): - format = Format.BINARY oid = _oids.TIMETZ_OID @@ -144,7 +138,6 @@ class _BaseDatetimeTextDumper(_BaseDatetimeDumper): class DatetimeDumper(_BaseDatetimeTextDumper): - oid = _oids.TIMESTAMPTZ_OID def upgrade(self, obj: datetime, format: PyFormat) -> Dumper: @@ -155,12 +148,10 @@ class DatetimeDumper(_BaseDatetimeTextDumper): class DatetimeNoTzDumper(_BaseDatetimeTextDumper): - oid = _oids.TIMESTAMP_OID class DatetimeBinaryDumper(_BaseDatetimeDumper): - format = Format.BINARY oid = _oids.TIMESTAMPTZ_OID @@ -177,7 +168,6 @@ class DatetimeBinaryDumper(_BaseDatetimeDumper): class DatetimeNoTzBinaryDumper(_BaseDatetimeDumper): - format = Format.BINARY oid = _oids.TIMESTAMP_OID @@ -188,7 +178,6 @@ class DatetimeNoTzBinaryDumper(_BaseDatetimeDumper): class TimedeltaDumper(Dumper): - oid = _oids.INTERVAL_OID def __init__(self, cls: type, context: Optional[AdaptContext] = None): @@ -216,7 +205,6 @@ class TimedeltaDumper(Dumper): class TimedeltaBinaryDumper(Dumper): - format = Format.BINARY oid = _oids.INTERVAL_OID @@ -226,7 +214,6 @@ class TimedeltaBinaryDumper(Dumper): class DateLoader(Loader): - _ORDER_YMD = 0 _ORDER_DMY = 1 _ORDER_MDY = 2 @@ -270,7 +257,6 @@ class DateLoader(Loader): class DateBinaryLoader(Loader): - format = Format.BINARY def load(self, data: Buffer) -> date: @@ -285,7 +271,6 @@ class DateBinaryLoader(Loader): class TimeLoader(Loader): - _re_format = re.compile(rb"^(\d+):(\d+):(\d+)(?:\.(\d+))?") def load(self, data: Buffer) -> time: @@ -312,7 +297,6 @@ class TimeLoader(Loader): class TimeBinaryLoader(Loader): - format = Format.BINARY def load(self, data: Buffer) -> time: @@ -327,7 +311,6 @@ class TimeBinaryLoader(Loader): class TimetzLoader(Loader): - _re_format = re.compile( rb"""(?ix) ^ @@ -369,7 +352,6 @@ class TimetzLoader(Loader): class TimetzBinaryLoader(Loader): - format = Format.BINARY def load(self, data: Buffer) -> time: @@ -386,7 +368,6 @@ class TimetzBinaryLoader(Loader): class TimestampLoader(Loader): - _re_format = re.compile( rb"""(?ix) ^ @@ -472,7 +453,6 @@ class TimestampLoader(Loader): class TimestampBinaryLoader(Loader): - format = Format.BINARY def load(self, data: Buffer) -> datetime: @@ -487,7 +467,6 @@ class TimestampBinaryLoader(Loader): class TimestamptzLoader(Loader): - _re_format = re.compile( rb"""(?ix) ^ @@ -563,7 +542,6 @@ class TimestamptzLoader(Loader): class TimestamptzBinaryLoader(Loader): - format = Format.BINARY def __init__(self, oid: int, context: Optional[AdaptContext] = None): @@ -600,7 +578,6 @@ class TimestamptzBinaryLoader(Loader): class IntervalLoader(Loader): - _re_interval = re.compile( rb""" (?: ([-+]?\d+) \s+ years? \s* )? # Years @@ -660,7 +637,6 @@ class IntervalLoader(Loader): class IntervalBinaryLoader(Loader): - format = Format.BINARY def load(self, data: Buffer) -> timedelta: diff --git a/psycopg/psycopg/types/hstore.py b/psycopg/psycopg/types/hstore.py index f668da8c6..86d7913f3 100644 --- a/psycopg/psycopg/types/hstore.py +++ b/psycopg/psycopg/types/hstore.py @@ -51,7 +51,6 @@ class BaseHstoreDumper(RecursiveDumper): tokens.append('"') for k, v in obj.items(): - if not isinstance(k, str): raise e.DataError("hstore keys can only be strings") add_token(k) diff --git a/psycopg/psycopg/types/json.py b/psycopg/psycopg/types/json.py index fc4a6d6f3..3683bf2cb 100644 --- a/psycopg/psycopg/types/json.py +++ b/psycopg/psycopg/types/json.py @@ -118,7 +118,6 @@ class Jsonb(_JsonWrapper): class _JsonDumper(Dumper): - # The globally used JSON dumps() function. It can be changed globally (by # set_json_dumps) or by a subclass. _dumps: JsonDumpsFunction = json.dumps @@ -133,23 +132,19 @@ class _JsonDumper(Dumper): class JsonDumper(_JsonDumper): - oid = _oids.JSON_OID class JsonBinaryDumper(_JsonDumper): - format = Format.BINARY oid = _oids.JSON_OID class JsonbDumper(_JsonDumper): - oid = _oids.JSONB_OID class JsonbBinaryDumper(_JsonDumper): - format = Format.BINARY oid = _oids.JSONB_OID @@ -159,7 +154,6 @@ class JsonbBinaryDumper(_JsonDumper): class _JsonLoader(Loader): - # The globally used JSON loads() function. It can be changed globally (by # set_json_loads) or by a subclass. _loads: JsonLoadsFunction = json.loads @@ -188,7 +182,6 @@ class JsonBinaryLoader(_JsonLoader): class JsonbBinaryLoader(_JsonLoader): - format = Format.BINARY def load(self, data: Buffer) -> Any: diff --git a/psycopg/psycopg/types/multirange.py b/psycopg/psycopg/types/multirange.py index 2fa1c67aa..623ac36f6 100644 --- a/psycopg/psycopg/types/multirange.py +++ b/psycopg/psycopg/types/multirange.py @@ -278,7 +278,6 @@ class MultirangeDumper(BaseMultirangeDumper): class MultirangeBinaryDumper(BaseMultirangeDumper): - format = Format.BINARY def dump(self, obj: Multirange[Any]) -> Buffer: @@ -297,7 +296,6 @@ class MultirangeBinaryDumper(BaseMultirangeDumper): class BaseMultirangeLoader(RecursiveLoader, Generic[T]): - subtype_oid: int def __init__(self, oid: int, context: Optional[AdaptContext] = None): @@ -352,7 +350,6 @@ _END_INT = ord("}") class MultirangeBinaryLoader(BaseMultirangeLoader[T]): - format = Format.BINARY def load(self, data: Buffer) -> Multirange[T]: diff --git a/psycopg/psycopg/types/net.py b/psycopg/psycopg/types/net.py index 99a023e9b..983de9a03 100644 --- a/psycopg/psycopg/types/net.py +++ b/psycopg/psycopg/types/net.py @@ -50,7 +50,6 @@ class _LazyIpaddress: class InterfaceDumper(Dumper): - oid = _oids.INET_OID def dump(self, obj: Interface) -> bytes: @@ -58,7 +57,6 @@ class InterfaceDumper(Dumper): class NetworkDumper(Dumper): - oid = _oids.CIDR_OID def dump(self, obj: Network) -> bytes: @@ -109,7 +107,6 @@ class InetBinaryDumper(_AIBinaryDumper, _LazyIpaddress): class NetworkBinaryDumper(Dumper): - format = Format.BINARY oid = _oids.CIDR_OID @@ -138,7 +135,6 @@ class InetLoader(_LazyIpaddressLoader): class InetBinaryLoader(_LazyIpaddressLoader): - format = Format.BINARY def load(self, data: Buffer) -> Union[Address, Interface]: @@ -168,7 +164,6 @@ class CidrLoader(_LazyIpaddressLoader): class CidrBinaryLoader(_LazyIpaddressLoader): - format = Format.BINARY def load(self, data: Buffer) -> Network: diff --git a/psycopg/psycopg/types/numeric.py b/psycopg/psycopg/types/numeric.py index ada6e942e..1d421afa8 100644 --- a/psycopg/psycopg/types/numeric.py +++ b/psycopg/psycopg/types/numeric.py @@ -49,7 +49,6 @@ class _IntDumper(Dumper): class _SpecialValuesDumper(Dumper): - _special: Dict[bytes, bytes] = {} def dump(self, obj: Any) -> bytes: @@ -65,7 +64,6 @@ class _SpecialValuesDumper(Dumper): class FloatDumper(_SpecialValuesDumper): - oid = _oids.FLOAT8_OID _special = { @@ -80,7 +78,6 @@ class Float4Dumper(FloatDumper): class FloatBinaryDumper(Dumper): - format = Format.BINARY oid = _oids.FLOAT8_OID @@ -89,7 +86,6 @@ class FloatBinaryDumper(Dumper): class Float4BinaryDumper(FloatBinaryDumper): - oid = _oids.FLOAT4_OID def dump(self, obj: float) -> bytes: @@ -97,7 +93,6 @@ class Float4BinaryDumper(FloatBinaryDumper): class DecimalDumper(_SpecialValuesDumper): - oid = _oids.NUMERIC_OID def dump(self, obj: Decimal) -> bytes: @@ -163,7 +158,6 @@ class IntDumper(Dumper): class Int2BinaryDumper(Int2Dumper): - format = Format.BINARY def dump(self, obj: int) -> bytes: @@ -171,7 +165,6 @@ class Int2BinaryDumper(Int2Dumper): class Int4BinaryDumper(Int4Dumper): - format = Format.BINARY def dump(self, obj: int) -> bytes: @@ -179,7 +172,6 @@ class Int4BinaryDumper(Int4Dumper): class Int8BinaryDumper(Int8Dumper): - format = Format.BINARY def dump(self, obj: int) -> bytes: @@ -192,7 +184,6 @@ BIT_PER_PGDIGIT = log(2) / log(10_000) class IntNumericBinaryDumper(IntNumericDumper): - format = Format.BINARY def dump(self, obj: int) -> Buffer: @@ -200,7 +191,6 @@ class IntNumericBinaryDumper(IntNumericDumper): class OidBinaryDumper(OidDumper): - format = Format.BINARY def dump(self, obj: int) -> bytes: @@ -208,7 +198,6 @@ class OidBinaryDumper(OidDumper): class IntBinaryDumper(IntDumper): - format = Format.BINARY _int2_dumper = Int2BinaryDumper(Int2) @@ -224,7 +213,6 @@ class IntLoader(Loader): class Int2BinaryLoader(Loader): - format = Format.BINARY def load(self, data: Buffer) -> int: @@ -232,7 +220,6 @@ class Int2BinaryLoader(Loader): class Int4BinaryLoader(Loader): - format = Format.BINARY def load(self, data: Buffer) -> int: @@ -240,7 +227,6 @@ class Int4BinaryLoader(Loader): class Int8BinaryLoader(Loader): - format = Format.BINARY def load(self, data: Buffer) -> int: @@ -248,7 +234,6 @@ class Int8BinaryLoader(Loader): class OidBinaryLoader(Loader): - format = Format.BINARY def load(self, data: Buffer) -> int: @@ -262,7 +247,6 @@ class FloatLoader(Loader): class Float4BinaryLoader(Loader): - format = Format.BINARY def load(self, data: Buffer) -> float: @@ -270,7 +254,6 @@ class Float4BinaryLoader(Loader): class Float8BinaryLoader(Loader): - format = Format.BINARY def load(self, data: Buffer) -> float: @@ -331,7 +314,6 @@ _pack_numeric_head = cast( class NumericBinaryLoader(Loader): - format = Format.BINARY def load(self, data: Buffer) -> Decimal: @@ -361,7 +343,6 @@ NUMERIC_NINF_BIN = _pack_numeric_head(0, 0, NUMERIC_NINF, 0) class DecimalBinaryDumper(Dumper): - format = Format.BINARY oid = _oids.NUMERIC_OID @@ -378,7 +359,6 @@ class NumericDumper(DecimalDumper): class NumericBinaryDumper(Dumper): - format = Format.BINARY oid = _oids.NUMERIC_OID diff --git a/psycopg/psycopg/types/range.py b/psycopg/psycopg/types/range.py index 98ad7c44d..649f3ce05 100644 --- a/psycopg/psycopg/types/range.py +++ b/psycopg/psycopg/types/range.py @@ -396,7 +396,6 @@ _re_esc = re.compile(rb"([\\\"])") class RangeBinaryDumper(BaseRangeDumper): - format = Format.BINARY def dump(self, obj: Range[Any]) -> Buffer: @@ -517,7 +516,6 @@ _re_undouble = re.compile(rb'(["\\])\1') class RangeBinaryLoader(BaseRangeLoader[T]): - format = Format.BINARY def load(self, data: Buffer) -> Range[T]: diff --git a/psycopg/psycopg/types/string.py b/psycopg/psycopg/types/string.py index 113186679..a0adc5650 100644 --- a/psycopg/psycopg/types/string.py +++ b/psycopg/psycopg/types/string.py @@ -56,17 +56,14 @@ class _StrDumper(_BaseStrDumper): class StrBinaryDumper(_StrBinaryDumper): - oid = _oids.TEXT_OID class StrBinaryDumperVarchar(_StrBinaryDumper): - oid = _oids.VARCHAR_OID class StrBinaryDumperName(_StrBinaryDumper): - oid = _oids.NAME_OID @@ -84,12 +81,10 @@ class StrDumper(_StrDumper): class StrDumperVarchar(_StrDumper): - oid = _oids.VARCHAR_OID class StrDumperName(_StrDumper): - oid = _oids.NAME_OID @@ -126,12 +121,10 @@ class TextLoader(Loader): class TextBinaryLoader(TextLoader): - format = Format.BINARY class BytesDumper(Dumper): - oid = _oids.BYTEA_OID _qprefix = b"" @@ -169,7 +162,6 @@ class BytesDumper(Dumper): class BytesBinaryDumper(Dumper): - format = Format.BINARY oid = _oids.BYTEA_OID @@ -178,7 +170,6 @@ class BytesBinaryDumper(Dumper): class ByteaLoader(Loader): - _escaping: "EscapingProto" def __init__(self, oid: int, context: Optional[AdaptContext] = None): @@ -191,7 +182,6 @@ class ByteaLoader(Loader): class ByteaBinaryLoader(Loader): - format = Format.BINARY def load(self, data: Buffer) -> Buffer: diff --git a/psycopg/psycopg/types/uuid.py b/psycopg/psycopg/types/uuid.py index f9f35d54f..6e0d8156b 100644 --- a/psycopg/psycopg/types/uuid.py +++ b/psycopg/psycopg/types/uuid.py @@ -19,7 +19,6 @@ UUID: Callable[..., "uuid.UUID"] = None # type: ignore[assignment] class UUIDDumper(Dumper): - oid = _oids.UUID_OID def dump(self, obj: "uuid.UUID") -> bytes: @@ -27,7 +26,6 @@ class UUIDDumper(Dumper): class UUIDBinaryDumper(UUIDDumper): - format = Format.BINARY def dump(self, obj: "uuid.UUID") -> bytes: @@ -48,7 +46,6 @@ class UUIDLoader(Loader): class UUIDBinaryLoader(UUIDLoader): - format = Format.BINARY def load(self, data: Buffer) -> "uuid.UUID": diff --git a/psycopg/setup.cfg b/psycopg/setup.cfg index d96f747f1..089fa4ee2 100644 --- a/psycopg/setup.cfg +++ b/psycopg/setup.cfg @@ -72,7 +72,7 @@ test = pytest-cov >= 3.0 pytest-randomly >= 3.5 dev = - black >= 22.3.0 + black >= 23.1.0 dnspython >= 2.1 flake8 >= 4.0 mypy >= 0.990 diff --git a/psycopg_pool/psycopg_pool/base.py b/psycopg_pool/psycopg_pool/base.py index c081419e7..fe29408c3 100644 --- a/psycopg_pool/psycopg_pool/base.py +++ b/psycopg_pool/psycopg_pool/base.py @@ -16,7 +16,6 @@ from ._compat import Counter, Deque class BasePool(Generic[ConnectionType]): - # Used to generate pool names _num_pool = 0 diff --git a/psycopg_pool/psycopg_pool/pool.py b/psycopg_pool/psycopg_pool/pool.py index 05cfc8fea..dd50d73a6 100644 --- a/psycopg_pool/psycopg_pool/pool.py +++ b/psycopg_pool/psycopg_pool/pool.py @@ -351,7 +351,6 @@ class ConnectionPool(BasePool[Connection[Any]]): connections: Sequence[Connection[Any]] = (), timeout: float = 0.0, ) -> None: - # Stop the scheduler self._sched.enter(0, None) diff --git a/tests/constraints.txt b/tests/constraints.txt index 5c86d5a3a..a254f2907 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 == 22.3.0 +black == 23.1.0 dnspython == 2.1.0 flake8 == 4.0.0 types-setuptools == 57.4.0 diff --git a/tests/pool/test_null_pool.py b/tests/pool/test_null_pool.py index c0e80603f..51cc67ad9 100644 --- a/tests/pool/test_null_pool.py +++ b/tests/pool/test_null_pool.py @@ -191,7 +191,6 @@ def test_reset(dsn): with NullConnectionPool(dsn, max_size=1, reset=reset) as p: with p.connection() as conn: - # Queue the worker so it will take the same connection a second time # instead of making a new one. t = Thread(target=worker) @@ -225,7 +224,6 @@ def test_reset_badstate(dsn, caplog): with NullConnectionPool(dsn, max_size=1, reset=reset) as p: with p.connection() as conn: - t = Thread(target=worker) t.start() ensure_waiting(p) @@ -257,7 +255,6 @@ def test_reset_broken(dsn, caplog): with NullConnectionPool(dsn, max_size=1, reset=reset) as p: with p.connection() as conn: - t = Thread(target=worker) t.start() ensure_waiting(p) diff --git a/tests/pool/test_null_pool_async.py b/tests/pool/test_null_pool_async.py index 23a1a5221..d33eecb4d 100644 --- a/tests/pool/test_null_pool_async.py +++ b/tests/pool/test_null_pool_async.py @@ -193,7 +193,6 @@ async def test_reset(dsn): async with AsyncNullConnectionPool(dsn, max_size=1, reset=reset) as p: async with p.connection() as conn: - # Queue the worker so it will take the same connection a second time # instead of making a new one. t = create_task(worker()) @@ -226,7 +225,6 @@ async def test_reset_badstate(dsn, caplog): async with AsyncNullConnectionPool(dsn, max_size=1, reset=reset) as p: async with p.connection() as conn: - t = create_task(worker()) await ensure_waiting(p) @@ -257,7 +255,6 @@ async def test_reset_broken(dsn, caplog): async with AsyncNullConnectionPool(dsn, max_size=1, reset=reset) as p: async with p.connection() as conn: - t = create_task(worker()) await ensure_waiting(p) diff --git a/tests/pool/test_pool.py b/tests/pool/test_pool.py index 30c790b10..29c4bf554 100644 --- a/tests/pool/test_pool.py +++ b/tests/pool/test_pool.py @@ -812,7 +812,6 @@ def test_grow(dsn, monkeypatch, min_size, want_times): @pytest.mark.slow @pytest.mark.timing def test_shrink(dsn, monkeypatch): - from psycopg_pool.pool import ShrinkPool results: List[Tuple[int, int]] = [] diff --git a/tests/pool/test_pool_async.py b/tests/pool/test_pool_async.py index 286a77524..27f9f452c 100644 --- a/tests/pool/test_pool_async.py +++ b/tests/pool/test_pool_async.py @@ -766,7 +766,6 @@ async def test_grow(dsn, monkeypatch, min_size, want_times): @pytest.mark.slow @pytest.mark.timing async def test_shrink(dsn, monkeypatch): - from psycopg_pool.pool_async import ShrinkPool results: List[Tuple[int, int]] = [] diff --git a/tests/scripts/bench-411.py b/tests/scripts/bench-411.py index a4d1af302..bf137db61 100644 --- a/tests/scripts/bench-411.py +++ b/tests/scripts/bench-411.py @@ -30,7 +30,6 @@ data: List[Dict[str, Any]] = [] def main() -> None: - args = parse_cmdline() ids[:] = range(args.ntests) diff --git a/tests/test_adapt.py b/tests/test_adapt.py index 9ca469bfb..31668d20e 100644 --- a/tests/test_adapt.py +++ b/tests/test_adapt.py @@ -133,7 +133,6 @@ def test_subclass_dumper(conn): def test_dumper_protocol(conn): - # This class doesn't inherit from adapt.Dumper but passes a mypy check from .adapters_example import MyStrDumper @@ -146,7 +145,6 @@ def test_dumper_protocol(conn): def test_loader_protocol(conn): - # This class doesn't inherit from adapt.Loader but passes a mypy check from .adapters_example import MyTextLoader @@ -392,7 +390,6 @@ def test_no_cast_needed(conn, fmt_in): @pytest.mark.slow @pytest.mark.skipif(_psycopg is None, reason="C module test") def test_optimised_adapters(): - # All the optimised adapters available c_adapters = {} for n in dir(_psycopg): diff --git a/tests/test_dns_srv.py b/tests/test_dns_srv.py index 15b370685..857491ccd 100644 --- a/tests/test_dns_srv.py +++ b/tests/test_dns_srv.py @@ -57,9 +57,7 @@ def test_srv(conninfo, want, env, fake_srv, setpgenv): async def test_srv_async(conninfo, want, env, afake_srv, setpgenv): setpgenv(env) params = conninfo_to_dict(conninfo) - params = await ( - psycopg._dns.resolve_srv_async(params) # type: ignore[attr-defined] - ) + params = await psycopg._dns.resolve_srv_async(params) # type: ignore[attr-defined] assert conninfo_to_dict(want) == params diff --git a/tests/test_tpc.py b/tests/test_tpc.py index 91a04e067..f1ef16cb6 100644 --- a/tests/test_tpc.py +++ b/tests/test_tpc.py @@ -181,7 +181,7 @@ class TestTPC: # check the values returned assert len(okvals) == len(xids) - for (xid, (gid, prepared, owner, database)) in zip(xids, okvals): + for xid, (gid, prepared, owner, database) in zip(xids, okvals): assert xid.gtrid == gid assert xid.prepared == prepared assert xid.owner == owner diff --git a/tests/test_tpc_async.py b/tests/test_tpc_async.py index a409a2e82..a829c4c12 100644 --- a/tests/test_tpc_async.py +++ b/tests/test_tpc_async.py @@ -185,7 +185,7 @@ class TestTPC: # check the values returned assert len(okvals) == len(xids) - for (xid, (gid, prepared, owner, database)) in zip(xids, okvals): + for xid, (gid, prepared, owner, database) in zip(xids, okvals): assert xid.gtrid == gid assert xid.prepared == prepared assert xid.owner == owner diff --git a/tests/test_typeinfo.py b/tests/test_typeinfo.py index f715539af..56dab053d 100644 --- a/tests/test_typeinfo.py +++ b/tests/test_typeinfo.py @@ -69,7 +69,6 @@ _info_cls = pytest.mark.parametrize( @_status @_info_cls def test_fetch_not_found(conn, name, status, info_cls, monkeypatch): - if TypeInfo._has_to_regtype_function(conn): exit_orig = psycopg.Transaction.__exit__ @@ -93,7 +92,6 @@ def test_fetch_not_found(conn, name, status, info_cls, monkeypatch): @_status @_info_cls async def test_fetch_not_found_async(aconn, name, status, info_cls, monkeypatch): - if TypeInfo._has_to_regtype_function(aconn): exit_orig = psycopg.AsyncTransaction.__aexit__ diff --git a/tests/types/test_array.py b/tests/types/test_array.py index 74c17a614..b0db15132 100644 --- a/tests/types/test_array.py +++ b/tests/types/test_array.py @@ -263,7 +263,6 @@ def test_dump_list_no_comma_separator(conn): self.coords = (x1, y1, x2, y2) class BoxDumper(Dumper): - format = pq.Format.TEXT oid = psycopg.postgres.types["box"].oid diff --git a/tests/types/test_bool.py b/tests/types/test_bool.py index edd4dad7a..73f394d13 100644 --- a/tests/types/test_bool.py +++ b/tests/types/test_bool.py @@ -26,7 +26,6 @@ def test_roundtrip_bool(conn, b, fmt_in, fmt_out): @pytest.mark.parametrize("val", [True, False]) def test_quote_bool(conn, val): - tx = Transformer() assert tx.get_dumper(val, PyFormat.TEXT).quote(val) == str(val).lower().encode( "ascii" @@ -38,7 +37,6 @@ def test_quote_bool(conn, val): def test_quote_none(conn): - tx = Transformer() assert tx.get_dumper(None, PyFormat.TEXT).quote(None) == b"NULL" diff --git a/tests/types/test_none.py b/tests/types/test_none.py index 4c008fd78..94827a3a0 100644 --- a/tests/types/test_none.py +++ b/tests/types/test_none.py @@ -3,7 +3,6 @@ from psycopg.adapt import Transformer, PyFormat def test_quote_none(conn): - tx = Transformer() assert tx.get_dumper(None, PyFormat.TEXT).quote(None) == b"NULL" diff --git a/tools/update_oids.py b/tools/update_oids.py index 3eb8f2a29..22f04ec53 100755 --- a/tools/update_oids.py +++ b/tools/update_oids.py @@ -104,7 +104,7 @@ def get_version_comment(conn: Connection) -> List[str]: def get_py_oids(conn: Connection) -> List[str]: lines = [] - for (typname, oid) in conn.execute( + for typname, oid in conn.execute( """ select typname, oid from pg_type @@ -125,7 +125,7 @@ def get_py_types(conn: Connection) -> List[str]: # Note: "record" is a pseudotype but still a useful one to have. # "pg_lsn" is a documented public type and useful in streaming replication lines = [] - for (typname, oid, typarray, regtype, typdelim) in conn.execute( + for typname, oid, typarray, regtype, typdelim in conn.execute( """ select typname, oid, typarray, -- CRDB might have quotes in the regtype representation @@ -160,7 +160,7 @@ order by typname def get_py_ranges(conn: Connection) -> List[str]: lines = [] - for (typname, oid, typarray, rngsubtype) in conn.execute( + for typname, oid, typarray, rngsubtype in conn.execute( """ select typname, oid, typarray, rngsubtype from @@ -180,7 +180,7 @@ order by typname def get_py_multiranges(conn: Connection) -> List[str]: lines = [] - for (typname, oid, typarray, rngtypid, rngsubtype) in conn.execute( + for typname, oid, typarray, rngtypid, rngsubtype in conn.execute( """ select typname, oid, typarray, rngtypid, rngsubtype from @@ -203,7 +203,7 @@ order by typname def get_cython_oids(conn: Connection) -> List[str]: lines = [] - for (typname, oid) in conn.execute( + for typname, oid in conn.execute( """ select typname, oid from pg_type