mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-09-21 03:08:57 +03:00
Upgrade f-strings with flynt -a and remove int()
This commit is contained in:
parent
8d7f660309
commit
c3b65d63b6
|
@ -477,7 +477,7 @@ class MinTimeLoggingConnection(LoggingConnection):
|
||||||
if t > self._mintime:
|
if t > self._mintime:
|
||||||
if isinstance(msg, bytes):
|
if isinstance(msg, bytes):
|
||||||
msg = msg.decode(_ext.encodings[self.encoding], 'replace')
|
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):
|
def cursor(self, *args, **kwargs):
|
||||||
kwargs.setdefault('cursor_factory',
|
kwargs.setdefault('cursor_factory',
|
||||||
|
@ -603,7 +603,7 @@ class ReplicationCursor(_replicationCursor):
|
||||||
raise psycopg2.ProgrammingError(
|
raise psycopg2.ProgrammingError(
|
||||||
"cannot specify timeline for logical replication")
|
"cannot specify timeline for logical replication")
|
||||||
|
|
||||||
command += " TIMELINE %d" % timeline
|
command += f" TIMELINE {timeline}"
|
||||||
|
|
||||||
if options:
|
if options:
|
||||||
if slot_type == REPLICATION_PHYSICAL:
|
if slot_type == REPLICATION_PHYSICAL:
|
||||||
|
@ -869,7 +869,7 @@ class HstoreAdapter:
|
||||||
for m in self._re_hstore.finditer(s):
|
for m in self._re_hstore.finditer(s):
|
||||||
if m is None or m.start() != start:
|
if m is None or m.start() != start:
|
||||||
raise psycopg2.InterfaceError(
|
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))
|
k = _bsdec.sub(r'\1', m.group(1))
|
||||||
v = m.group(2)
|
v = m.group(2)
|
||||||
if v is not None:
|
if v is not None:
|
||||||
|
@ -880,7 +880,7 @@ class HstoreAdapter:
|
||||||
|
|
||||||
if start < len(s):
|
if start < len(s):
|
||||||
raise psycopg2.InterfaceError(
|
raise psycopg2.InterfaceError(
|
||||||
"error parsing hstore: unparsed data after char %d" % start)
|
f"error parsing hstore: unparsed data after char {start}")
|
||||||
|
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
|
|
|
@ -39,24 +39,24 @@ def main():
|
||||||
sys.stdout.write(f"test suite {test.__name__}\n")
|
sys.stdout.write(f"test suite {test.__name__}\n")
|
||||||
|
|
||||||
for i in range(1, opt.nruns + 1):
|
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 = unittest.TextTestRunner()
|
||||||
runner.run(test.test_suite())
|
runner.run(test.test_suite())
|
||||||
dump(i, opt)
|
dump(i, opt)
|
||||||
|
|
||||||
f1 = open('debug-%02d.txt' % (opt.nruns - 1)).readlines()
|
f1 = open(f'debug-{(opt.nruns - 1):02}.txt').readlines()
|
||||||
f2 = open('debug-%02d.txt' % opt.nruns).readlines()
|
f2 = open(f'debug-{opt.nruns:02}.txt').readlines()
|
||||||
for line in difflib.unified_diff(f1, f2,
|
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)
|
sys.stdout.write(line)
|
||||||
|
|
||||||
rv = f1 != f2 and 1 or 0
|
rv = f1 != f2 and 1 or 0
|
||||||
|
|
||||||
if opt.objs:
|
if opt.objs:
|
||||||
f1 = open('objs-%02d.txt' % (opt.nruns - 1)).readlines()
|
f1 = open(f'objs-{(opt.nruns - 1):02}.txt').readlines()
|
||||||
f2 = open('objs-%02d.txt' % opt.nruns).readlines()
|
f2 = open(f'objs-{opt.nruns:02}.txt').readlines()
|
||||||
for line in difflib.unified_diff(f1, f2,
|
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)
|
sys.stdout.write(line)
|
||||||
|
|
||||||
return rv
|
return rv
|
||||||
|
@ -85,7 +85,7 @@ def dump(i, opt):
|
||||||
|
|
||||||
pprint(
|
pprint(
|
||||||
sorted(((v, str(k)) for k, v in c.items()), reverse=True),
|
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:
|
if opt.objs:
|
||||||
co = []
|
co = []
|
||||||
|
@ -100,7 +100,7 @@ def dump(i, opt):
|
||||||
else:
|
else:
|
||||||
co.sort()
|
co.sort()
|
||||||
|
|
||||||
pprint(co, stream=open("objs-%02d.txt" % i, "w"))
|
pprint(co, stream=open(f"objs-{i:02}.txt", "w"))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -19,7 +19,7 @@ class TwoPhaseCommitTests(unittest.TestCase):
|
||||||
def make_xid(self, con):
|
def make_xid(self, con):
|
||||||
id = TwoPhaseCommitTests._last_id
|
id = TwoPhaseCommitTests._last_id
|
||||||
TwoPhaseCommitTests._last_id += 1
|
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):
|
def test_xid(self):
|
||||||
con = self.connect()
|
con = self.connect()
|
||||||
|
|
|
@ -302,7 +302,7 @@ class ConnectionTests(ConnectingTestCase):
|
||||||
# Stop the committer thread
|
# Stop the committer thread
|
||||||
stop.append(True)
|
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):
|
def test_connect_cursor_factory(self):
|
||||||
conn = self.connect(cursor_factory=psycopg2.extras.DictCursor)
|
conn = self.connect(cursor_factory=psycopg2.extras.DictCursor)
|
||||||
|
|
|
@ -246,7 +246,7 @@ class CopyTests(ConnectingTestCase):
|
||||||
curs.copy_expert, 'COPY tcopy (data) FROM STDIN', f)
|
curs.copy_expert, 'COPY tcopy (data) FROM STDIN', f)
|
||||||
|
|
||||||
def test_copy_no_column_limit(self):
|
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 = self.conn.cursor()
|
||||||
curs.execute('CREATE TEMPORARY TABLE manycols (%s)' % ',\n'.join(
|
curs.execute('CREATE TEMPORARY TABLE manycols (%s)' % ',\n'.join(
|
||||||
|
|
|
@ -309,7 +309,7 @@ def skip_before_libpq(*ver):
|
||||||
v = libpq_version()
|
v = libpq_version()
|
||||||
decorator = unittest.skipIf(
|
decorator = unittest.skipIf(
|
||||||
v < int("%d%02d%02d" % ver),
|
v < int("%d%02d%02d" % ver),
|
||||||
"skipped because libpq %d" % v,
|
f"skipped because libpq {v}",
|
||||||
)
|
)
|
||||||
return decorator(cls)
|
return decorator(cls)
|
||||||
return skip_before_libpq_
|
return skip_before_libpq_
|
||||||
|
|
Loading…
Reference in New Issue
Block a user