Skip to content

Commit d67f5ab

Browse files
committed
Check that variables are used inside loops
1 parent 23d54b8 commit d67f5ab

11 files changed

+73
-73
lines changed

dbutils/simple_pooled_db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def __init__(self, dbapi, maxconnections, *args, **kwargs):
159159
"Database module threading support cannot be determined.")
160160
# Establish all database connections (it would be better to
161161
# only establish a part of them now, and the rest on demand).
162-
for i in range(maxconnections):
162+
for _i in range(maxconnections):
163163
self.addConnection(dbapi.connect(*args, **kwargs))
164164

165165
# The following functions are used with DB-API 2 modules

dbutils/simple_pooled_pg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def __init__(self, maxconnections, *args, **kwargs):
122122
self._queue = Queue(maxconnections)
123123
# Establish all database connections (it would be better to
124124
# only establish a part of them now, and the rest on demand).
125-
for i in range(maxconnections):
125+
for _i in range(maxconnections):
126126
self.cache(PgConnection(*args, **kwargs))
127127

128128
def cache(self, con):

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ select = [
5050
]
5151
# You can use `ruff rule ...` to see what these ignored rules check
5252
ignore = [
53-
"B007",
5453
"B904",
5554
"E722",
5655
"N811",

tests/test_persistent_db.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_threads(dbapi): # noqa: F811
6767
num_threads = 3
6868
persist = PersistentDB(dbapi, closeable=True)
6969
query_queue, result_queue = [], []
70-
for i in range(num_threads):
70+
for _i in range(num_threads):
7171
query_queue.append(Queue(1))
7272
result_queue.append(Queue(1))
7373

@@ -164,7 +164,7 @@ def test_setsession(dbapi): # noqa: F811
164164
cursor.execute('set test')
165165
cursor.fetchone()
166166
cursor.close()
167-
for i in range(3):
167+
for _i in range(3):
168168
assert db._con.session == ['datestyle', 'test']
169169
cursor = db.cursor()
170170
cursor.execute('select test')

tests/test_persistent_pg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_threads():
4545
num_threads = 3
4646
persist = PersistentPg()
4747
query_queue, result_queue = [], []
48-
for i in range(num_threads):
48+
for _i in range(num_threads):
4949
query_queue.append(Queue(1))
5050
result_queue.append(Queue(1))
5151

@@ -132,7 +132,7 @@ def test_setsession():
132132
assert db._setsession_sql == ('set datestyle',)
133133
assert db.db.session == ['datestyle']
134134
db.query('set test')
135-
for i in range(3):
135+
for _i in range(3):
136136
assert db.db.session == ['datestyle', 'test']
137137
db.query('select test')
138138
assert db.db.session == ['datestyle']

tests/test_pooled_db.py

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def close(what=closed):
275275
if shareable:
276276
assert len(pool._shared_cache) == 0
277277
cache = []
278-
for i in range(5):
278+
for _i in range(5):
279279
cache.append(pool.connection())
280280
assert len(pool._idle_cache) == 5
281281
if shareable:
@@ -297,7 +297,7 @@ def close_shared(what=closed):
297297

298298
if shareable:
299299
cache = []
300-
for i in range(5):
300+
for _i in range(5):
301301
cache.append(pool.connection())
302302
pool._shared_cache[3].con.close = close_shared
303303
else:
@@ -407,63 +407,64 @@ def test_min_max_cached(dbapi, threadsafety): # noqa: F811
407407
shareable = threadsafety > 1
408408
pool = PooledDB(dbapi, 3)
409409
assert len(pool._idle_cache) == 3
410-
cache = [pool.connection() for i in range(3)]
410+
cache = [pool.connection() for _i in range(3)]
411411
assert len(pool._idle_cache) == 0
412412
assert cache
413413
del cache
414414
assert len(pool._idle_cache) == 3
415-
cache = [pool.connection() for i in range(6)]
415+
cache = [pool.connection() for _i in range(6)]
416416
assert len(pool._idle_cache) == 0
417417
assert cache
418418
del cache
419419
assert len(pool._idle_cache) == 6
420420
pool = PooledDB(dbapi, 0, 3)
421421
assert len(pool._idle_cache) == 0
422-
cache = [pool.connection() for i in range(3)]
422+
cache = [pool.connection() for _i in range(3)]
423423
assert len(pool._idle_cache) == 0
424424
assert cache
425425
del cache
426426
assert len(pool._idle_cache) == 3
427-
cache = [pool.connection() for i in range(6)]
427+
cache = [pool.connection() for _i in range(6)]
428428
assert len(pool._idle_cache) == 0
429429
assert cache
430430
del cache
431431
assert len(pool._idle_cache) == 3
432432
pool = PooledDB(dbapi, 3, 3)
433433
assert len(pool._idle_cache) == 3
434-
cache = [pool.connection() for i in range(3)]
434+
cache = [pool.connection() for _i in range(3)]
435435
assert len(pool._idle_cache) == 0
436436
assert cache
437437
del cache
438438
assert len(pool._idle_cache) == 3
439-
cache = [pool.connection() for i in range(6)]
439+
cache = [pool.connection() for _i in range(6)]
440440
assert len(pool._idle_cache) == 0
441441
assert cache
442442
del cache
443443
assert len(pool._idle_cache) == 3
444444
pool = PooledDB(dbapi, 3, 2)
445445
assert len(pool._idle_cache) == 3
446-
cache = [pool.connection() for i in range(4)]
446+
cache = [pool.connection() for _i in range(4)]
447447
assert len(pool._idle_cache) == 0
448448
assert cache
449449
del cache
450450
assert len(pool._idle_cache) == 3
451451
pool = PooledDB(dbapi, 2, 5)
452452
assert len(pool._idle_cache) == 2
453-
cache = [pool.connection() for i in range(10)]
453+
cache = [pool.connection() for _i in range(10)]
454454
assert len(pool._idle_cache) == 0
455455
assert cache
456456
del cache
457457
assert len(pool._idle_cache) == 5
458458
pool = PooledDB(dbapi, 1, 2, 3)
459459
assert len(pool._idle_cache) == 1
460-
cache = [pool.connection(False) for i in range(4)]
460+
cache = [pool.connection(False) for _i in range(4)]
461461
assert len(pool._idle_cache) == 0
462462
if shareable:
463463
assert len(pool._shared_cache) == 0
464+
assert cache
464465
del cache
465466
assert len(pool._idle_cache) == 2
466-
cache = [pool.connection() for i in range(10)]
467+
cache = [pool.connection() for _i in range(10)]
467468
assert len(pool._idle_cache) == 0
468469
if shareable:
469470
assert len(pool._shared_cache) == 3
@@ -474,14 +475,14 @@ def test_min_max_cached(dbapi, threadsafety): # noqa: F811
474475
assert len(pool._shared_cache) == 0
475476
pool = PooledDB(dbapi, 1, 3, 2)
476477
assert len(pool._idle_cache) == 1
477-
cache = [pool.connection(False) for i in range(4)]
478+
cache = [pool.connection(False) for _i in range(4)]
478479
assert len(pool._idle_cache) == 0
479480
if shareable:
480481
assert len(pool._shared_cache) == 0
481482
assert cache
482483
del cache
483484
assert len(pool._idle_cache) == 3
484-
cache = [pool.connection() for i in range(10)]
485+
cache = [pool.connection() for _i in range(10)]
485486
if shareable:
486487
assert len(pool._idle_cache) == 1
487488
assert len(pool._shared_cache) == 2
@@ -500,34 +501,34 @@ def test_max_shared(dbapi, threadsafety): # noqa: F811
500501
shareable = threadsafety > 1
501502
pool = PooledDB(dbapi)
502503
assert len(pool._idle_cache) == 0
503-
cache = [pool.connection() for i in range(10)]
504+
cache = [pool.connection() for _i in range(10)]
504505
assert len(cache) == 10
505506
assert len(pool._idle_cache) == 0
506507
pool = PooledDB(dbapi, 1, 1, 0)
507508
assert len(pool._idle_cache) == 1
508-
cache = [pool.connection() for i in range(10)]
509+
cache = [pool.connection() for _i in range(10)]
509510
assert len(cache) == 10
510511
assert len(pool._idle_cache) == 0
511512
pool = PooledDB(dbapi, 0, 0, 1)
512-
cache = [pool.connection() for i in range(10)]
513+
cache = [pool.connection() for _i in range(10)]
513514
assert len(cache) == 10
514515
assert len(pool._idle_cache) == 0
515516
if shareable:
516517
assert len(pool._shared_cache) == 1
517518
pool = PooledDB(dbapi, 1, 1, 1)
518519
assert len(pool._idle_cache) == 1
519-
cache = [pool.connection() for i in range(10)]
520+
cache = [pool.connection() for _i in range(10)]
520521
assert len(cache) == 10
521522
assert len(pool._idle_cache) == 0
522523
if shareable:
523524
assert len(pool._shared_cache) == 1
524525
pool = PooledDB(dbapi, 0, 0, 7)
525-
cache = [pool.connection(False) for i in range(3)]
526+
cache = [pool.connection(False) for _i in range(3)]
526527
assert len(cache) == 3
527528
assert len(pool._idle_cache) == 0
528529
if shareable:
529530
assert len(pool._shared_cache) == 0
530-
cache = [pool.connection() for i in range(10)]
531+
cache = [pool.connection() for _i in range(10)]
531532
assert len(cache) == 10
532533
assert len(pool._idle_cache) == 3
533534
if shareable:
@@ -537,7 +538,7 @@ def test_max_shared(dbapi, threadsafety): # noqa: F811
537538
def test_sort_shared(dbapi): # noqa: F811
538539
pool = PooledDB(dbapi, 0, 4, 4)
539540
cache = []
540-
for i in range(6):
541+
for _i in range(6):
541542
db = pool.connection()
542543
db.cursor().execute('select test')
543544
cache.append(db)
@@ -559,7 +560,7 @@ def test_equally_shared(dbapi, threadsafety): # noqa: F811
559560
shareable = threadsafety > 1
560561
pool = PooledDB(dbapi, 5, 5, 5)
561562
assert len(pool._idle_cache) == 5
562-
for i in range(15):
563+
for _i in range(15):
563564
db = pool.connection(False)
564565
db.cursor().execute('select test')
565566
db.close()
@@ -569,7 +570,7 @@ def test_equally_shared(dbapi, threadsafety): # noqa: F811
569570
assert con._usage == 3
570571
assert con._con.num_queries == 3
571572
cache = []
572-
for i in range(35):
573+
for _i in range(35):
573574
db = pool.connection()
574575
db.cursor().execute('select test')
575576
cache.append(db)
@@ -595,7 +596,7 @@ def test_many_shared(dbapi, threadsafety): # noqa: F811
595596
shareable = threadsafety > 1
596597
pool = PooledDB(dbapi, 0, 0, 5)
597598
cache = []
598-
for i in range(35):
599+
for _i in range(35):
599600
db = pool.connection()
600601
db.cursor().execute('select test1')
601602
db.cursor().execute('select test2')
@@ -622,7 +623,7 @@ def test_many_shared(dbapi, threadsafety): # noqa: F811
622623
for db in cache:
623624
if db:
624625
db.cursor().callproc('test4')
625-
for i in range(6):
626+
for _i in range(6):
626627
db = pool.connection()
627628
db.cursor().callproc('test4')
628629
cache.append(db)
@@ -685,7 +686,7 @@ def test_maxconnections(dbapi, threadsafety): # noqa: F811, PLR0915
685686
assert pool._connections == 0
686687
assert len(pool._idle_cache) == 1
687688
cache = []
688-
for i in range(3):
689+
for _i in range(3):
689690
cache.append(pool.connection(False))
690691
assert pool._connections == 3
691692
assert len(pool._idle_cache) == 0
@@ -700,7 +701,7 @@ def test_maxconnections(dbapi, threadsafety): # noqa: F811, PLR0915
700701
assert len(pool._idle_cache) == 2
701702
if shareable:
702703
assert len(pool._shared_cache) == 0
703-
for i in range(3):
704+
for _i in range(3):
704705
cache.append(pool.connection())
705706
assert len(pool._idle_cache) == 0
706707
if shareable:
@@ -794,7 +795,7 @@ def test_maxconnections(dbapi, threadsafety): # noqa: F811, PLR0915
794795
assert pool._connections == 0
795796
assert len(pool._idle_cache) == 4
796797
cache = []
797-
for i in range(4):
798+
for _i in range(4):
798799
cache.append(pool.connection(False))
799800
assert pool._connections == 4
800801
assert len(pool._idle_cache) == 0
@@ -806,7 +807,7 @@ def test_maxconnections(dbapi, threadsafety): # noqa: F811, PLR0915
806807
assert pool._maxconnections == 4
807808
assert pool._connections == 0
808809
assert len(pool._idle_cache) == 1
809-
for i in range(4):
810+
for _i in range(4):
810811
cache.append(pool.connection())
811812
assert len(pool._idle_cache) == 0
812813
if shareable:
@@ -826,7 +827,7 @@ def test_maxconnections(dbapi, threadsafety): # noqa: F811, PLR0915
826827
assert pool._maxconnections == 3
827828
assert pool._connections == 0
828829
cache = []
829-
for i in range(3):
830+
for _i in range(3):
830831
cache.append(pool.connection(False))
831832
assert pool._connections == 3
832833
with pytest.raises(TooManyConnections):
@@ -835,11 +836,11 @@ def test_maxconnections(dbapi, threadsafety): # noqa: F811, PLR0915
835836
pool.connection(True)
836837
cache = []
837838
assert pool._connections == 0
838-
for i in range(3):
839+
for _i in range(3):
839840
cache.append(pool.connection())
840841
assert pool._connections == 3
841842
if shareable:
842-
for i in range(3):
843+
for _i in range(3):
843844
cache.append(pool.connection())
844845
assert pool._connections == 3
845846
else:
@@ -851,7 +852,7 @@ def test_maxconnections(dbapi, threadsafety): # noqa: F811, PLR0915
851852
assert pool._maxconnections == 0
852853
assert pool._connections == 0
853854
cache = []
854-
for i in range(10):
855+
for _i in range(10):
855856
cache.append(pool.connection(False))
856857
cache.append(pool.connection())
857858
if shareable:
@@ -967,40 +968,40 @@ def test_one_thread_two_connections(dbapi, threadsafety): # noqa: F811
967968
shareable = threadsafety > 1
968969
pool = PooledDB(dbapi, 2)
969970
db1 = pool.connection()
970-
for i in range(5):
971+
for _i in range(5):
971972
db1.cursor().execute('select test')
972973
db2 = pool.connection()
973974
assert db1 != db2
974975
assert db1._con != db2._con
975-
for i in range(7):
976+
for _i in range(7):
976977
db2.cursor().execute('select test')
977978
assert db1._con._con.num_queries == 5
978979
assert db2._con._con.num_queries == 7
979980
del db1
980981
db1 = pool.connection()
981982
assert db1 != db2
982983
assert db1._con != db2._con
983-
for i in range(3):
984+
for _i in range(3):
984985
db1.cursor().execute('select test')
985986
assert db1._con._con.num_queries == 8
986987
db2.cursor().execute('select test')
987988
assert db2._con._con.num_queries == 8
988989
pool = PooledDB(dbapi, 0, 0, 2)
989990
db1 = pool.connection()
990-
for i in range(5):
991+
for _i in range(5):
991992
db1.cursor().execute('select test')
992993
db2 = pool.connection()
993994
assert db1 != db2
994995
assert db1._con != db2._con
995-
for i in range(7):
996+
for _i in range(7):
996997
db2.cursor().execute('select test')
997998
assert db1._con._con.num_queries == 5
998999
assert db2._con._con.num_queries == 7
9991000
del db1
10001001
db1 = pool.connection()
10011002
assert db1 != db2
10021003
assert db1._con != db2._con
1003-
for i in range(3):
1004+
for _i in range(3):
10041005
db1.cursor().execute('select test')
10051006
assert db1._con._con.num_queries == 8
10061007
db2.cursor().execute('select test')
@@ -1028,7 +1029,7 @@ def test_three_threads_two_connections(dbapi, threadsafety): # noqa: F811
10281029
def connection():
10291030
queue.put(pool.connection(), timeout=1)
10301031

1031-
for i in range(3):
1032+
for _i in range(3):
10321033
Thread(target=connection).start()
10331034
db1 = queue.get(timeout=1)
10341035
db2 = queue.get(timeout=1)

0 commit comments

Comments
 (0)