summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHugo van Kemenade <hugovk@users.noreply.github.com>2020-11-17 21:37:42 +0200
committerHugo van Kemenade <hugovk@users.noreply.github.com>2020-11-17 22:22:11 +0200
commit7babeccbececd9dd02642dfd193a3c3a0fc0dbe7 (patch)
treefe83142e2763e9d922edbb97b16db6f46bb84a52 /lib
parent6c48b63ae4a70da6dbbc5b6eef20806d7f505950 (diff)
downloadpsycopg2-7babeccbececd9dd02642dfd193a3c3a0fc0dbe7.tar.gz
Upgrade Python syntax with pyupgrade --py36-plus
Diffstat (limited to 'lib')
-rw-r--r--lib/_json.py2
-rw-r--r--lib/_range.py10
-rw-r--r--lib/extensions.py6
-rw-r--r--lib/extras.py92
-rw-r--r--lib/pool.py2
-rw-r--r--lib/sql.py18
-rw-r--r--lib/tz.py2
7 files changed, 66 insertions, 66 deletions
diff --git a/lib/_json.py b/lib/_json.py
index e5958b9..1664d06 100644
--- a/lib/_json.py
+++ b/lib/_json.py
@@ -43,7 +43,7 @@ JSONB_OID = 3802
JSONBARRAY_OID = 3807
-class Json(object):
+class Json:
"""
An `~psycopg2.extensions.ISQLQuote` wrapper to adapt a Python object to
:sql:`json` data type.
diff --git a/lib/_range.py b/lib/_range.py
index 499f501..1db11f8 100644
--- a/lib/_range.py
+++ b/lib/_range.py
@@ -32,7 +32,7 @@ from psycopg2.extensions import ISQLQuote, adapt, register_adapter
from psycopg2.extensions import new_type, new_array_type, register_type
-class Range(object):
+class Range:
"""Python representation for a PostgreSQL |range|_ type.
:param lower: lower bound for the range. `!None` means unbound
@@ -59,7 +59,7 @@ class Range(object):
if self._bounds is None:
return "%s(empty=True)" % self.__class__.__name__
else:
- return "%s(%r, %r, %r)" % (self.__class__.__name__,
+ return "{}({!r}, {!r}, {!r})".format(self.__class__.__name__,
self._lower, self._upper, self._bounds)
def __str__(self):
@@ -238,7 +238,7 @@ def register_range(pgrange, pyrange, conn_or_curs, globally=False):
return caster
-class RangeAdapter(object):
+class RangeAdapter:
"""`ISQLQuote` adapter for `Range` subclasses.
This is an abstract class: concrete classes must set a `name` class
@@ -286,7 +286,7 @@ class RangeAdapter(object):
+ b", '" + r._bounds.encode('utf8') + b"')"
-class RangeCaster(object):
+class RangeCaster:
"""Helper class to convert between `Range` and PostgreSQL range types.
Objects of this class are usually created by `register_range()`. Manual
@@ -503,7 +503,7 @@ class NumberRangeAdapter(RangeAdapter):
else:
upper = ''
- return ("'%s%s,%s%s'" % (
+ return ("'{}{},{}{}'".format(
r._bounds[0], lower, upper, r._bounds[1])).encode('ascii')
diff --git a/lib/extensions.py b/lib/extensions.py
index c4a6618..1de6607 100644
--- a/lib/extensions.py
+++ b/lib/extensions.py
@@ -106,7 +106,7 @@ def register_adapter(typ, callable):
# The SQL_IN class is the official adapter for tuples starting from 2.0.6.
-class SQL_IN(object):
+class SQL_IN:
"""Adapt any iterable to an SQL quotable object."""
def __init__(self, seq):
self._seq = seq
@@ -130,7 +130,7 @@ class SQL_IN(object):
return str(self.getquoted())
-class NoneAdapter(object):
+class NoneAdapter:
"""Adapt None to NULL.
This adapter is not used normally as a fast path in mogrify uses NULL,
@@ -168,7 +168,7 @@ def make_dsn(dsn=None, **kwargs):
tmp.update(kwargs)
kwargs = tmp
- dsn = " ".join(["%s=%s" % (k, _param_escape(str(v)))
+ dsn = " ".join(["{}={}".format(k, _param_escape(str(v)))
for (k, v) in kwargs.items()])
# verify that the returned dsn is valid
diff --git a/lib/extras.py b/lib/extras.py
index 3b42be7..3f1da84 100644
--- a/lib/extras.py
+++ b/lib/extras.py
@@ -72,47 +72,47 @@ class DictCursorBase(_cursor):
else:
raise NotImplementedError(
"DictCursorBase can't be instantiated without a row factory.")
- super(DictCursorBase, self).__init__(*args, **kwargs)
+ super().__init__(*args, **kwargs)
self._query_executed = False
self._prefetch = False
self.row_factory = row_factory
def fetchone(self):
if self._prefetch:
- res = super(DictCursorBase, self).fetchone()
+ res = super().fetchone()
if self._query_executed:
self._build_index()
if not self._prefetch:
- res = super(DictCursorBase, self).fetchone()
+ res = super().fetchone()
return res
def fetchmany(self, size=None):
if self._prefetch:
- res = super(DictCursorBase, self).fetchmany(size)
+ res = super().fetchmany(size)
if self._query_executed:
self._build_index()
if not self._prefetch:
- res = super(DictCursorBase, self).fetchmany(size)
+ res = super().fetchmany(size)
return res
def fetchall(self):
if self._prefetch:
- res = super(DictCursorBase, self).fetchall()
+ res = super().fetchall()
if self._query_executed:
self._build_index()
if not self._prefetch:
- res = super(DictCursorBase, self).fetchall()
+ res = super().fetchall()
return res
def __iter__(self):
try:
if self._prefetch:
- res = super(DictCursorBase, self).__iter__()
+ res = super().__iter__()
first = next(res)
if self._query_executed:
self._build_index()
if not self._prefetch:
- res = super(DictCursorBase, self).__iter__()
+ res = super().__iter__()
first = next(res)
yield first
@@ -126,7 +126,7 @@ class DictConnection(_connection):
"""A connection that uses `DictCursor` automatically."""
def cursor(self, *args, **kwargs):
kwargs.setdefault('cursor_factory', self.cursor_factory or DictCursor)
- return super(DictConnection, self).cursor(*args, **kwargs)
+ return super().cursor(*args, **kwargs)
class DictCursor(DictCursorBase):
@@ -137,18 +137,18 @@ class DictCursor(DictCursorBase):
def __init__(self, *args, **kwargs):
kwargs['row_factory'] = DictRow
- super(DictCursor, self).__init__(*args, **kwargs)
+ super().__init__(*args, **kwargs)
self._prefetch = True
def execute(self, query, vars=None):
self.index = OrderedDict()
self._query_executed = True
- return super(DictCursor, self).execute(query, vars)
+ return super().execute(query, vars)
def callproc(self, procname, vars=None):
self.index = OrderedDict()
self._query_executed = True
- return super(DictCursor, self).callproc(procname, vars)
+ return super().callproc(procname, vars)
def _build_index(self):
if self._query_executed and self.description:
@@ -169,22 +169,22 @@ class DictRow(list):
def __getitem__(self, x):
if not isinstance(x, (int, slice)):
x = self._index[x]
- return super(DictRow, self).__getitem__(x)
+ return super().__getitem__(x)
def __setitem__(self, x, v):
if not isinstance(x, (int, slice)):
x = self._index[x]
- super(DictRow, self).__setitem__(x, v)
+ super().__setitem__(x, v)
def items(self):
- g = super(DictRow, self).__getitem__
+ g = super().__getitem__
return ((n, g(self._index[n])) for n in self._index)
def keys(self):
return iter(self._index)
def values(self):
- g = super(DictRow, self).__getitem__
+ g = super().__getitem__
return (g(self._index[n]) for n in self._index)
def get(self, x, default=None):
@@ -201,7 +201,7 @@ class DictRow(list):
def __reduce__(self):
# this is apparently useless, but it fixes #1073
- return super(DictRow, self).__reduce__()
+ return super().__reduce__()
def __getstate__(self):
return self[:], self._index.copy()
@@ -215,7 +215,7 @@ class RealDictConnection(_connection):
"""A connection that uses `RealDictCursor` automatically."""
def cursor(self, *args, **kwargs):
kwargs.setdefault('cursor_factory', self.cursor_factory or RealDictCursor)
- return super(RealDictConnection, self).cursor(*args, **kwargs)
+ return super().cursor(*args, **kwargs)
class RealDictCursor(DictCursorBase):
@@ -228,17 +228,17 @@ class RealDictCursor(DictCursorBase):
"""
def __init__(self, *args, **kwargs):
kwargs['row_factory'] = RealDictRow
- super(RealDictCursor, self).__init__(*args, **kwargs)
+ super().__init__(*args, **kwargs)
def execute(self, query, vars=None):
self.column_mapping = []
self._query_executed = True
- return super(RealDictCursor, self).execute(query, vars)
+ return super().execute(query, vars)
def callproc(self, procname, vars=None):
self.column_mapping = []
self._query_executed = True
- return super(RealDictCursor, self).callproc(procname, vars)
+ return super().callproc(procname, vars)
def _build_index(self):
if self._query_executed and self.description:
@@ -256,7 +256,7 @@ class RealDictRow(OrderedDict):
else:
cursor = None
- super(RealDictRow, self).__init__(*args, **kwargs)
+ super().__init__(*args, **kwargs)
if cursor is not None:
# Required for named cursors
@@ -272,20 +272,20 @@ class RealDictRow(OrderedDict):
if RealDictRow in self:
# We are in the row building phase
mapping = self[RealDictRow]
- super(RealDictRow, self).__setitem__(mapping[key], value)
+ super().__setitem__(mapping[key], value)
if key == len(mapping) - 1:
# Row building finished
del self[RealDictRow]
return
- super(RealDictRow, self).__setitem__(key, value)
+ super().__setitem__(key, value)
class NamedTupleConnection(_connection):
"""A connection that uses `NamedTupleCursor` automatically."""
def cursor(self, *args, **kwargs):
kwargs.setdefault('cursor_factory', self.cursor_factory or NamedTupleCursor)
- return super(NamedTupleConnection, self).cursor(*args, **kwargs)
+ return super().cursor(*args, **kwargs)
class NamedTupleCursor(_cursor):
@@ -309,18 +309,18 @@ class NamedTupleCursor(_cursor):
def execute(self, query, vars=None):
self.Record = None
- return super(NamedTupleCursor, self).execute(query, vars)
+ return super().execute(query, vars)
def executemany(self, query, vars):
self.Record = None
- return super(NamedTupleCursor, self).executemany(query, vars)
+ return super().executemany(query, vars)
def callproc(self, procname, vars=None):
self.Record = None
- return super(NamedTupleCursor, self).callproc(procname, vars)
+ return super().callproc(procname, vars)
def fetchone(self):
- t = super(NamedTupleCursor, self).fetchone()
+ t = super().fetchone()
if t is not None:
nt = self.Record
if nt is None:
@@ -328,14 +328,14 @@ class NamedTupleCursor(_cursor):
return nt._make(t)
def fetchmany(self, size=None):
- ts = super(NamedTupleCursor, self).fetchmany(size)
+ ts = super().fetchmany(size)
nt = self.Record
if nt is None:
nt = self.Record = self._make_nt()
return list(map(nt._make, ts))
def fetchall(self):
- ts = super(NamedTupleCursor, self).fetchall()
+ ts = super().fetchall()
nt = self.Record
if nt is None:
nt = self.Record = self._make_nt()
@@ -343,7 +343,7 @@ class NamedTupleCursor(_cursor):
def __iter__(self):
try:
- it = super(NamedTupleCursor, self).__iter__()
+ it = super().__iter__()
t = next(it)
nt = self.Record
@@ -438,7 +438,7 @@ class LoggingConnection(_connection):
def cursor(self, *args, **kwargs):
self._check()
kwargs.setdefault('cursor_factory', self.cursor_factory or LoggingCursor)
- return super(LoggingConnection, self).cursor(*args, **kwargs)
+ return super().cursor(*args, **kwargs)
class LoggingCursor(_cursor):
@@ -446,13 +446,13 @@ class LoggingCursor(_cursor):
def execute(self, query, vars=None):
try:
- return super(LoggingCursor, self).execute(query, vars)
+ return super().execute(query, vars)
finally:
self.connection.log(self.query, self)
def callproc(self, procname, vars=None):
try:
- return super(LoggingCursor, self).callproc(procname, vars)
+ return super().callproc(procname, vars)
finally:
self.connection.log(self.query, self)
@@ -501,14 +501,14 @@ class LogicalReplicationConnection(_replicationConnection):
def __init__(self, *args, **kwargs):
kwargs['replication_type'] = REPLICATION_LOGICAL
- super(LogicalReplicationConnection, self).__init__(*args, **kwargs)
+ super().__init__(*args, **kwargs)
class PhysicalReplicationConnection(_replicationConnection):
def __init__(self, *args, **kwargs):
kwargs['replication_type'] = REPLICATION_PHYSICAL
- super(PhysicalReplicationConnection, self).__init__(*args, **kwargs)
+ super().__init__(*args, **kwargs)
class StopReplication(Exception):
@@ -592,9 +592,9 @@ class ReplicationCursor(_replicationCursor):
if type(start_lsn) is str:
lsn = start_lsn.split('/')
- lsn = "%X/%08X" % (int(lsn[0], 16), int(lsn[1], 16))
+ lsn = "{:X}/{:08X}".format(int(lsn[0], 16), int(lsn[1], 16))
else:
- lsn = "%X/%08X" % ((start_lsn >> 32) & 0xFFFFFFFF,
+ lsn = "{:X}/{:08X}".format((start_lsn >> 32) & 0xFFFFFFFF,
start_lsn & 0xFFFFFFFF)
command += lsn
@@ -615,7 +615,7 @@ class ReplicationCursor(_replicationCursor):
for k, v in options.items():
if not command.endswith('('):
command += ", "
- command += "%s %s" % (quote_ident(k, self), _A(str(v)))
+ command += "{} {}".format(quote_ident(k, self), _A(str(v)))
command += ")"
self.start_replication_expert(
@@ -628,7 +628,7 @@ class ReplicationCursor(_replicationCursor):
# a dbtype and adapter for Python UUID type
-class UUID_adapter(object):
+class UUID_adapter:
"""Adapt Python's uuid.UUID__ type to PostgreSQL's uuid__.
.. __: https://docs.python.org/library/uuid.html
@@ -683,7 +683,7 @@ def register_uuid(oids=None, conn_or_curs=None):
# a type, dbtype and adapter for PostgreSQL inet type
-class Inet(object):
+class Inet:
"""Wrap a string to allow for correct SQL-quoting of inet values.
Note that this adapter does NOT check the passed value to make
@@ -695,7 +695,7 @@ class Inet(object):
self.addr = addr
def __repr__(self):
- return "%s(%r)" % (self.__class__.__name__, self.addr)
+ return f"{self.__class__.__name__}({self.addr!r})"
def prepare(self, conn):
self._conn = conn
@@ -790,7 +790,7 @@ def _solve_conn_curs(conn_or_curs):
return conn, curs
-class HstoreAdapter(object):
+class HstoreAdapter:
"""Adapt a Python dict to the hstore syntax."""
def __init__(self, wrapped):
self.wrapped = wrapped
@@ -987,7 +987,7 @@ def register_hstore(conn_or_curs, globally=False, unicode=False,
_ext.register_type(HSTOREARRAY, not globally and conn_or_curs or None)
-class CompositeCaster(object):
+class CompositeCaster:
"""Helps conversion of a PostgreSQL composite type into a Python object.
The class is usually created by the `register_composite()` function.
diff --git a/lib/pool.py b/lib/pool.py
index 30a29c3..5b14a3a 100644
--- a/lib/pool.py
+++ b/lib/pool.py
@@ -33,7 +33,7 @@ class PoolError(psycopg2.Error):
pass
-class AbstractConnectionPool(object):
+class AbstractConnectionPool:
"""Generic key-based pooling code."""
def __init__(self, minconn, maxconn, *args, **kwargs):
diff --git a/lib/sql.py b/lib/sql.py
index 2077267..aeff748 100644
--- a/lib/sql.py
+++ b/lib/sql.py
@@ -32,7 +32,7 @@ from psycopg2 import extensions as ext
_formatter = string.Formatter()
-class Composable(object):
+class Composable:
"""
Abstract base class for objects that can be used to compose an SQL string.
@@ -50,7 +50,7 @@ class Composable(object):
self._wrapped = wrapped
def __repr__(self):
- return "%s(%r)" % (self.__class__.__name__, self._wrapped)
+ return f"{self.__class__.__name__}({self._wrapped!r})"
def as_string(self, context):
"""
@@ -109,7 +109,7 @@ class Composed(Composable):
"Composed elements must be Composable, got %r instead" % i)
wrapped.append(i)
- super(Composed, self).__init__(wrapped)
+ super().__init__(wrapped)
@property
def seq(self):
@@ -181,7 +181,7 @@ class SQL(Composable):
def __init__(self, string):
if not isinstance(string, str):
raise TypeError("SQL values must be strings")
- super(SQL, self).__init__(string)
+ super().__init__(string)
@property
def string(self):
@@ -326,7 +326,7 @@ class Identifier(Composable):
if not isinstance(s, str):
raise TypeError("SQL identifier parts must be strings")
- super(Identifier, self).__init__(strings)
+ super().__init__(strings)
@property
def strings(self):
@@ -344,7 +344,7 @@ class Identifier(Composable):
"the Identifier wraps more than one than one string")
def __repr__(self):
- return "%s(%s)" % (
+ return "{}({})".format(
self.__class__.__name__,
', '.join(map(repr, self._wrapped)))
@@ -432,7 +432,7 @@ class Placeholder(Composable):
elif name is not None:
raise TypeError("expected string or None as name, got %r" % name)
- super(Placeholder, self).__init__(name)
+ super().__init__(name)
@property
def name(self):
@@ -440,8 +440,8 @@ class Placeholder(Composable):
return self._wrapped
def __repr__(self):
- return "Placeholder(%r)" % (
- self._wrapped if self._wrapped is not None else '',)
+ return "Placeholder({!r})".format(
+ self._wrapped if self._wrapped is not None else '')
def as_string(self, context):
if self._wrapped is not None:
diff --git a/lib/tz.py b/lib/tz.py
index ccbe374..81cd8f8 100644
--- a/lib/tz.py
+++ b/lib/tz.py
@@ -65,7 +65,7 @@ class FixedOffsetTimezone(datetime.tzinfo):
try:
return cls._cache[key]
except KeyError:
- tz = super(FixedOffsetTimezone, cls).__new__(cls, offset, name)
+ tz = super().__new__(cls, offset, name)
cls._cache[key] = tz
return tz