Skip to content

Commit 5c7f047

Browse files
author
Erlend E. Aasland
committed
Address review: bring the types outside the assertRaises()
1 parent eee3044 commit 5c7f047

File tree

5 files changed

+12
-9
lines changed

5 files changed

+12
-9
lines changed

Lib/test/test_functools.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,8 @@ class TestCmpToKeyC(TestCmpToKey, unittest.TestCase):
951951
@support.cpython_only
952952
def test_uninitialised_new(self):
953953
# Prevent heap types from being created uninitialised (bpo-43916)
954-
self.assertRaises(TypeError, type(c_functools.cmp_to_key(None)))
954+
tp = type(c_functools.cmp_to_key(None))
955+
self.assertRaises(TypeError, tp)
955956

956957

957958
class TestCmpToKeyPy(TestCmpToKey, unittest.TestCase):

Lib/test/test_posix.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ def tearDown(self):
6262
def test_uninitialised_new(self):
6363
# Prevent heap types from being created uninitialised (bpo-43916)
6464
self.assertRaises(TypeError, posix.DirEntry)
65-
self.assertRaises(TypeError, type(posix.scandir()))
65+
tp = type(posix.scandir())
66+
self.assertRaises(TypeError, tp)
6667

6768
def testNoArgFunctions(self):
6869
# test posix functions which take no arguments and have

Lib/test/test_re.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,8 +2221,8 @@ def test_uninitialised_new(self):
22212221
self.assertRaises(TypeError, re.Match)
22222222
self.assertRaises(TypeError, re.Pattern)
22232223
pat = re.compile("")
2224-
scn = pat.scanner("")
2225-
self.assertRaises(TypeError, type(scn))
2224+
tp = type(pat.scanner(""))
2225+
self.assertRaises(TypeError, tp)
22262226

22272227

22282228
class ExternalTests(unittest.TestCase):

Lib/test/test_threading.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ def func(): pass
123123
def test_uninitialised_new(self):
124124
# Prevent heap types from being created uninitialised (bpo-43916)
125125
lock = threading.Lock()
126-
self.assertRaises(TypeError, type(lock))
126+
tp = type(lock)
127+
self.assertRaises(TypeError, tp)
127128

128129
# Create a bunch of threads, let each do some work, wait until all are
129130
# done.

Lib/test/test_zlib.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ def test_overflow(self):
132132
@support.cpython_only
133133
def test_uninitialised_new(self):
134134
# Prevent heap types from being created uninitialised (bpo-43916)
135-
comp = zlib.compressobj()
136-
decomp = zlib.decompressobj()
137-
self.assertRaises(TypeError, type(comp))
138-
self.assertRaises(TypeError, type(decomp))
135+
comp_type = type(zlib.compressobj())
136+
decomp_type = type(zlib.decompressobj())
137+
self.assertRaises(TypeError, comp_type)
138+
self.assertRaises(TypeError, decomp_type)
139139

140140

141141
class BaseCompressTestCase(object):

0 commit comments

Comments
 (0)