summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo van Kemenade <hugovk@users.noreply.github.com>2020-11-18 18:09:08 +0200
committerHugo van Kemenade <hugovk@users.noreply.github.com>2020-11-18 18:09:08 +0200
commitc3b65d63b6b5543024aee961ec33e1f456b75eab (patch)
treea96d37ccab31c5542562bde41d1c0f2c118d79d4
parent8d7f660309c8be0fb0b50439c335b89d5b31878d (diff)
downloadpsycopg2-c3b65d63b6b5543024aee961ec33e1f456b75eab.tar.gz
Upgrade f-strings with flynt -a and remove int()
-rw-r--r--lib/extras.py8
-rwxr-xr-xscripts/refcounter.py18
-rw-r--r--tests/dbapi20_tpc.py2
-rwxr-xr-xtests/test_connection.py2
-rwxr-xr-xtests/test_copy.py2
-rw-r--r--tests/testutils.py2
6 files changed, 17 insertions, 17 deletions
diff --git a/lib/extras.py b/lib/extras.py
index 3fa6255..be39165 100644
--- a/lib/extras.py
+++ b/lib/extras.py
@@ -477,7 +477,7 @@ class MinTimeLoggingConnection(LoggingConnection):
if t > self._mintime:
if isinstance(msg, bytes):
msg = msg.decode(_ext.encodings[self.encoding], 'replace')
- return msg + _os.linesep + " (execution time: %d ms)" % t
+ return f"{msg}{_os.linesep} (execution time: {t} ms)"
def cursor(self, *args, **kwargs):
kwargs.setdefault('cursor_factory',
@@ -603,7 +603,7 @@ class ReplicationCursor(_replicationCursor):
raise psycopg2.ProgrammingError(
"cannot specify timeline for logical replication")
- command += " TIMELINE %d" % timeline
+ command += f" TIMELINE {timeline}"
if options:
if slot_type == REPLICATION_PHYSICAL:
@@ -869,7 +869,7 @@ class HstoreAdapter:
for m in self._re_hstore.finditer(s):
if m is None or m.start() != start:
raise psycopg2.InterfaceError(
- "error parsing hstore pair at char %d" % start)
+ f"error parsing hstore pair at char {start}")
k = _bsdec.sub(r'\1', m.group(1))
v = m.group(2)
if v is not None:
@@ -880,7 +880,7 @@ class HstoreAdapter:
if start < len(s):
raise psycopg2.InterfaceError(
- "error parsing hstore: unparsed data after char %d" % start)
+ f"error parsing hstore: unparsed data after char {start}")
return rv
diff --git a/scripts/refcounter.py b/scripts/refcounter.py
index efe69a3..6de2f6d 100755
--- a/scripts/refcounter.py
+++ b/scripts/refcounter.py
@@ -39,24 +39,24 @@ def main():
sys.stdout.write(f"test suite {test.__name__}\n")
for i in range(1, opt.nruns + 1):
- sys.stdout.write("test suite run %d of %d\n" % (i, opt.nruns))
+ sys.stdout.write(f"test suite run {i} of {opt.nruns}\n")
runner = unittest.TextTestRunner()
runner.run(test.test_suite())
dump(i, opt)
- f1 = open('debug-%02d.txt' % (opt.nruns - 1)).readlines()
- f2 = open('debug-%02d.txt' % opt.nruns).readlines()
+ f1 = open(f'debug-{(opt.nruns - 1):02}.txt').readlines()
+ f2 = open(f'debug-{opt.nruns:02}.txt').readlines()
for line in difflib.unified_diff(f1, f2,
- "run %d" % (opt.nruns - 1), "run %d" % opt.nruns):
+ f"run {opt.nruns - 1}", f"run {opt.nruns}"):
sys.stdout.write(line)
rv = f1 != f2 and 1 or 0
if opt.objs:
- f1 = open('objs-%02d.txt' % (opt.nruns - 1)).readlines()
- f2 = open('objs-%02d.txt' % opt.nruns).readlines()
+ f1 = open(f'objs-{(opt.nruns - 1):02}.txt').readlines()
+ f2 = open(f'objs-{opt.nruns:02}.txt').readlines()
for line in difflib.unified_diff(f1, f2,
- "run %d" % (opt.nruns - 1), "run %d" % opt.nruns):
+ f"run {opt.nruns - 1}", f"run {opt.nruns}"):
sys.stdout.write(line)
return rv
@@ -85,7 +85,7 @@ def dump(i, opt):
pprint(
sorted(((v, str(k)) for k, v in c.items()), reverse=True),
- stream=open("debug-%02d.txt" % i, "w"))
+ stream=open(f"debug-{i:02}.txt", "w"))
if opt.objs:
co = []
@@ -100,7 +100,7 @@ def dump(i, opt):
else:
co.sort()
- pprint(co, stream=open("objs-%02d.txt" % i, "w"))
+ pprint(co, stream=open(f"objs-{i:02}.txt", "w"))
if __name__ == '__main__':
diff --git a/tests/dbapi20_tpc.py b/tests/dbapi20_tpc.py
index d4790f7..fccc775 100644
--- a/tests/dbapi20_tpc.py
+++ b/tests/dbapi20_tpc.py
@@ -19,7 +19,7 @@ class TwoPhaseCommitTests(unittest.TestCase):
def make_xid(self, con):
id = TwoPhaseCommitTests._last_id
TwoPhaseCommitTests._last_id += 1
- return con.xid(42, "%s%d" % (self._global_id_prefix, id), "qualifier")
+ return con.xid(42, f"{self._global_id_prefix}{id}", "qualifier")
def test_xid(self):
con = self.connect()
diff --git a/tests/test_connection.py b/tests/test_connection.py
index dc1d446..8281c1c 100755
--- a/tests/test_connection.py
+++ b/tests/test_connection.py
@@ -302,7 +302,7 @@ class ConnectionTests(ConnectingTestCase):
# Stop the committer thread
stop.append(True)
- self.assert_(not notices, "%d notices raised" % len(notices))
+ self.assert_(not notices, f"{len(notices)} notices raised")
def test_connect_cursor_factory(self):
conn = self.connect(cursor_factory=psycopg2.extras.DictCursor)
diff --git a/tests/test_copy.py b/tests/test_copy.py
index a8e8ff9..7002bf7 100755
--- a/tests/test_copy.py
+++ b/tests/test_copy.py
@@ -246,7 +246,7 @@ class CopyTests(ConnectingTestCase):
curs.copy_expert, 'COPY tcopy (data) FROM STDIN', f)
def test_copy_no_column_limit(self):
- cols = ["c%050d" % i for i in range(200)]
+ cols = [f"c{i:050}" for i in range(200)]
curs = self.conn.cursor()
curs.execute('CREATE TEMPORARY TABLE manycols (%s)' % ',\n'.join(
diff --git a/tests/testutils.py b/tests/testutils.py
index 007fda2..865416c 100644
--- a/tests/testutils.py
+++ b/tests/testutils.py
@@ -309,7 +309,7 @@ def skip_before_libpq(*ver):
v = libpq_version()
decorator = unittest.skipIf(
v < int("%d%02d%02d" % ver),
- "skipped because libpq %d" % v,
+ f"skipped because libpq {v}",
)
return decorator(cls)
return skip_before_libpq_