Skip to content

Commit 4f908e8

Browse files
pythongh-100129: Make the names of all classes in the types module resolvable
1 parent cd67c1b commit 4f908e8

32 files changed

+176
-173
lines changed

Lib/test/test_complex.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def split_zeros(x):
395395
self.assertRaises(TypeError, float, 5+3j)
396396
self.assertRaises(ValueError, complex, "")
397397
self.assertRaises(TypeError, complex, None)
398-
self.assertRaisesRegex(TypeError, "not 'NoneType'", complex, None)
398+
self.assertRaisesRegex(TypeError, "not 'types.NoneType'", complex, None)
399399
self.assertRaises(ValueError, complex, "\0")
400400
self.assertRaises(ValueError, complex, "3\09")
401401
self.assertRaises(TypeError, complex, "1", "2")

Lib/test/test_coroutines.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ async def foo():
565565
coro = foo()
566566

567567
check = lambda: self.assertRaisesRegex(
568-
TypeError, "'coroutine' object is not iterable")
568+
TypeError, r"'types\.CoroutineType' object is not iterable")
569569

570570
with check():
571571
list(coro)
@@ -597,7 +597,7 @@ async def foo():
597597
await bar()
598598

599599
check = lambda: self.assertRaisesRegex(
600-
TypeError, "'coroutine' object is not iterable")
600+
TypeError, r"'types\.CoroutineType' object is not iterable")
601601

602602
coro = foo()
603603
with check():
@@ -958,7 +958,7 @@ def test_corotype_1(self):
958958
self.assertIn('in coroutine', ct.throw.__doc__)
959959
self.assertIn('of the coroutine', ct.__dict__['__name__'].__doc__)
960960
self.assertIn('of the coroutine', ct.__dict__['__qualname__'].__doc__)
961-
self.assertEqual(ct.__name__, 'coroutine')
961+
self.assertEqual(ct.__name__, 'CoroutineType')
962962

963963
async def f(): pass
964964
c = f()

Lib/test/test_csv.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ class mydialect(csv.Dialect):
10321032
with self.assertRaises(csv.Error) as cm:
10331033
mydialect()
10341034
self.assertEqual(str(cm.exception),
1035-
'"delimiter" must be string, not NoneType')
1035+
'"delimiter" must be string, not types.NoneType')
10361036

10371037
def test_escapechar(self):
10381038
class mydialect(csv.Dialect):

Lib/test/test_descr.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4832,11 +4832,11 @@ class X:
48324832

48334833
def test_qualname(self):
48344834
descriptors = [str.lower, complex.real, float.real, int.__add__]
4835-
types = ['method', 'member', 'getset', 'wrapper']
4835+
types = ['Method', 'Member', 'GetSet', 'Wrapper']
48364836

48374837
# make sure we have an example of each type of descriptor
48384838
for d, n in zip(descriptors, types):
4839-
self.assertEqual(type(d).__name__, n + '_descriptor')
4839+
self.assertEqual(type(d).__name__, n + 'DescriptorType')
48404840

48414841
for d in descriptors:
48424842
qualname = d.__objclass__.__qualname__ + '.' + d.__name__

Lib/test/test_extcall.py

+20-22
Original file line numberDiff line numberDiff line change
@@ -263,73 +263,71 @@
263263
...
264264
TypeError: h() got an unexpected keyword argument 'e'
265265
266-
>>> h(*h)
266+
>>> h(*1)
267267
Traceback (most recent call last):
268268
...
269-
TypeError: test.test_extcall.h() argument after * must be an iterable, not function
269+
TypeError: test.test_extcall.h() argument after * must be an iterable, not int
270270
271-
>>> h(1, *h)
271+
>>> h(1, *2)
272272
Traceback (most recent call last):
273273
...
274-
TypeError: Value after * must be an iterable, not function
274+
TypeError: Value after * must be an iterable, not int
275275
276-
>>> h(*[1], *h)
276+
>>> h(*[1], *2)
277277
Traceback (most recent call last):
278278
...
279-
TypeError: Value after * must be an iterable, not function
279+
TypeError: Value after * must be an iterable, not int
280280
281-
>>> dir(*h)
281+
>>> dir(*1)
282282
Traceback (most recent call last):
283283
...
284-
TypeError: dir() argument after * must be an iterable, not function
284+
TypeError: dir() argument after * must be an iterable, not int
285285
286286
>>> nothing = None
287-
>>> nothing(*h)
287+
>>> nothing(*1)
288288
Traceback (most recent call last):
289289
...
290-
TypeError: None argument after * must be an iterable, \
291-
not function
290+
TypeError: None argument after * must be an iterable, not int
292291
293-
>>> h(**h)
292+
>>> h(**1)
294293
Traceback (most recent call last):
295294
...
296-
TypeError: test.test_extcall.h() argument after ** must be a mapping, not function
295+
TypeError: test.test_extcall.h() argument after ** must be a mapping, not int
297296
298297
>>> h(**[])
299298
Traceback (most recent call last):
300299
...
301300
TypeError: test.test_extcall.h() argument after ** must be a mapping, not list
302301
303-
>>> h(a=1, **h)
302+
>>> h(a=1, **2)
304303
Traceback (most recent call last):
305304
...
306-
TypeError: test.test_extcall.h() argument after ** must be a mapping, not function
305+
TypeError: test.test_extcall.h() argument after ** must be a mapping, not int
307306
308307
>>> h(a=1, **[])
309308
Traceback (most recent call last):
310309
...
311310
TypeError: test.test_extcall.h() argument after ** must be a mapping, not list
312311
313-
>>> h(**{'a': 1}, **h)
312+
>>> h(**{'a': 1}, **2)
314313
Traceback (most recent call last):
315314
...
316-
TypeError: test.test_extcall.h() argument after ** must be a mapping, not function
315+
TypeError: test.test_extcall.h() argument after ** must be a mapping, not int
317316
318317
>>> h(**{'a': 1}, **[])
319318
Traceback (most recent call last):
320319
...
321320
TypeError: test.test_extcall.h() argument after ** must be a mapping, not list
322321
323-
>>> dir(**h)
322+
>>> dir(**1)
324323
Traceback (most recent call last):
325324
...
326-
TypeError: dir() argument after ** must be a mapping, not function
325+
TypeError: dir() argument after ** must be a mapping, not int
327326
328-
>>> nothing(**h)
327+
>>> nothing(**1)
329328
Traceback (most recent call last):
330329
...
331-
TypeError: None argument after ** must be a mapping, \
332-
not function
330+
TypeError: None argument after ** must be a mapping, not int
333331
334332
>>> dir(b=1, **{'b': 1})
335333
Traceback (most recent call last):

Lib/test/test_funcattrs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def f(): print(a)
112112
self.assertIsInstance(c, tuple)
113113
self.assertEqual(len(c), 1)
114114
# don't have a type object handy
115-
self.assertEqual(c[0].__class__.__name__, "cell")
115+
self.assertEqual(c[0].__class__.__name__, "CellType")
116116
self.cannot_set_attr(f, "__closure__", c, AttributeError)
117117

118118
def test_cell_new(self):

Lib/test/test_gdb.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ def test_pyup_command(self):
756756
self.assertMultilineMatches(bt,
757757
r'''^.*
758758
#[0-9]+ Frame 0x-?[0-9a-f]+, for file <string>, line 12, in baz \(args=\(1, 2, 3\)\)
759-
#[0-9]+ <built-in method pyobject_fastcall of module object at remote 0x[0-9a-f]+>
759+
#[0-9]+ <built-in method pyobject_fastcall of types.ModuleType object at remote 0x[0-9a-f]+>
760760
$''')
761761

762762
@unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands")
@@ -785,7 +785,7 @@ def test_up_then_down(self):
785785
self.assertMultilineMatches(bt,
786786
r'''^.*
787787
#[0-9]+ Frame 0x-?[0-9a-f]+, for file <string>, line 12, in baz \(args=\(1, 2, 3\)\)
788-
#[0-9]+ <built-in method pyobject_fastcall of module object at remote 0x[0-9a-f]+>
788+
#[0-9]+ <built-in method pyobject_fastcall of types.ModuleType object at remote 0x[0-9a-f]+>
789789
#[0-9]+ Frame 0x-?[0-9a-f]+, for file <string>, line 12, in baz \(args=\(1, 2, 3\)\)
790790
$''')
791791

@@ -799,7 +799,7 @@ def test_bt(self):
799799
self.assertMultilineMatches(bt,
800800
r'''^.*
801801
Traceback \(most recent call first\):
802-
<built-in method id of module object .*>
802+
<built-in method id of types\.ModuleType object .*>
803803
File ".*gdb_sample.py", line 10, in baz
804804
id\(42\)
805805
File ".*gdb_sample.py", line 7, in bar
@@ -1014,7 +1014,7 @@ def test_printing_builtin(self):
10141014
bt = self.get_stack_trace(script=self.get_sample_script(),
10151015
cmds_after_breakpoint=['py-up', 'py-print len'])
10161016
self.assertMultilineMatches(bt,
1017-
r".*\nbuiltin 'len' = <built-in method len of module object at remote 0x-?[0-9a-f]+>\n.*")
1017+
r".*\nbuiltin 'len' = <built-in method len of types\.ModuleType object at remote 0x-?[0-9a-f]+>\n.*")
10181018

10191019
class PyLocalsTests(DebuggerTests):
10201020
@unittest.skipIf(python_is_optimized(),

Lib/test/test_generators.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -977,10 +977,10 @@ def b():
977977
... yield 1
978978
...
979979
>>> type(g)
980-
<class 'function'>
980+
<class 'types.FunctionType'>
981981
>>> i = g()
982982
>>> type(i)
983-
<class 'generator'>
983+
<class 'types.GeneratorType'>
984984
>>> [s for s in dir(i) if not s.startswith('_')]
985985
['close', 'gi_code', 'gi_frame', 'gi_running', 'gi_suspended', 'gi_yieldfrom', 'send', 'throw']
986986
>>> from test.support import HAVE_DOCSTRINGS
@@ -997,11 +997,11 @@ def b():
997997
>>> i.gi_running
998998
0
999999
>>> type(i.gi_frame)
1000-
<class 'frame'>
1000+
<class 'types.FrameType'>
10011001
>>> i.gi_running = 42
10021002
Traceback (most recent call last):
10031003
...
1004-
AttributeError: attribute 'gi_running' of 'generator' objects is not writable
1004+
AttributeError: attribute 'gi_running' of 'types.GeneratorType' objects is not writable
10051005
>>> def g():
10061006
... yield me.gi_running
10071007
>>> me = g()
@@ -1372,27 +1372,27 @@ def b():
13721372
>>> def f():
13731373
... yield
13741374
>>> type(f())
1375-
<class 'generator'>
1375+
<class 'types.GeneratorType'>
13761376
13771377
13781378
>>> def f():
13791379
... if 0:
13801380
... yield
13811381
>>> type(f())
1382-
<class 'generator'>
1382+
<class 'types.GeneratorType'>
13831383
13841384
13851385
>>> def f():
13861386
... if 0:
13871387
... yield 1
13881388
>>> type(f())
1389-
<class 'generator'>
1389+
<class 'types.GeneratorType'>
13901390
13911391
>>> def f():
13921392
... if "":
13931393
... yield None
13941394
>>> type(f())
1395-
<class 'generator'>
1395+
<class 'types.GeneratorType'>
13961396
13971397
>>> def f():
13981398
... return
@@ -1416,15 +1416,15 @@ def b():
14161416
... x = 1
14171417
... return
14181418
>>> type(f())
1419-
<class 'generator'>
1419+
<class 'types.GeneratorType'>
14201420
14211421
>>> def f():
14221422
... if 0:
14231423
... def g():
14241424
... yield 1
14251425
...
14261426
>>> type(f())
1427-
<class 'NoneType'>
1427+
<class 'types.NoneType'>
14281428
14291429
>>> def f():
14301430
... if 0:
@@ -1434,15 +1434,15 @@ def b():
14341434
... def f(self):
14351435
... yield 2
14361436
>>> type(f())
1437-
<class 'NoneType'>
1437+
<class 'types.NoneType'>
14381438
14391439
>>> def f():
14401440
... if 0:
14411441
... return
14421442
... if 0:
14431443
... yield 2
14441444
>>> type(f())
1445-
<class 'generator'>
1445+
<class 'types.GeneratorType'>
14461446
14471447
This one caused a crash (see SF bug 567538):
14481448
@@ -2093,7 +2093,7 @@ def printsolution(self, x):
20932093
20942094
>>> def f(): list(i for i in [(yield 26)])
20952095
>>> type(f())
2096-
<class 'generator'>
2096+
<class 'types.GeneratorType'>
20972097
20982098
20992099
A yield expression with augmented assignment.
@@ -2364,21 +2364,21 @@ def printsolution(self, x):
23642364
23652365
>>> def f(): x += yield
23662366
>>> type(f())
2367-
<class 'generator'>
2367+
<class 'types.GeneratorType'>
23682368
23692369
>>> def f(): x = yield
23702370
>>> type(f())
2371-
<class 'generator'>
2371+
<class 'types.GeneratorType'>
23722372
23732373
>>> def f(): lambda x=(yield): 1
23742374
>>> type(f())
2375-
<class 'generator'>
2375+
<class 'types.GeneratorType'>
23762376
23772377
>>> def f(d): d[(yield "a")] = d[(yield "b")] = 27
23782378
>>> data = [1,2]
23792379
>>> g = f(data)
23802380
>>> type(g)
2381-
<class 'generator'>
2381+
<class 'types.GeneratorType'>
23822382
>>> g.send(None)
23832383
'a'
23842384
>>> data

Lib/test/test_genexps.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
4949
>>> g = (i*i for i in range(4))
5050
>>> type(g)
51-
<class 'generator'>
51+
<class 'types.GeneratorType'>
5252
>>> list(g)
5353
[0, 1, 4, 9]
5454

Lib/test/test_grammar.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1521,9 +1521,9 @@ def check(test):
15211521
msg=r'indices must be integers or slices, not dict;'
15221522
check('[[1, 2] [{3: 4}]]')
15231523
check('[[1, 2] [{i: i for i in range(5)}]]')
1524-
msg=r'indices must be integers or slices, not generator;'
1524+
msg=r'indices must be integers or slices, not types\.GeneratorType;'
15251525
check('[[1, 2] [(i for i in range(5))]]')
1526-
msg=r'indices must be integers or slices, not function;'
1526+
msg=r'indices must be integers or slices, not types\.FunctionType;'
15271527
check('[[1, 2] [(lambda x, y: x)]]')
15281528
msg=r'indices must be integers or slices, not str;'
15291529
check('[[1, 2] [f"{x}"]]')

Lib/test/test_json/test_fail.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def test_non_string_keys_dict(self):
100100
def test_not_serializable(self):
101101
import sys
102102
with self.assertRaisesRegex(TypeError,
103-
'Object of type module is not JSON serializable'):
103+
'Object of type ModuleType is not JSON serializable'):
104104
self.dumps(sys)
105105

106106
def test_truncated_input(self):

Lib/test/test_richcmp.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -258,16 +258,16 @@ class Spam:
258258
pass
259259

260260
tests = [
261-
(lambda: 42 < None, r"'<' .* of 'int' and 'NoneType'"),
262-
(lambda: None < 42, r"'<' .* of 'NoneType' and 'int'"),
263-
(lambda: 42 > None, r"'>' .* of 'int' and 'NoneType'"),
264-
(lambda: "foo" < None, r"'<' .* of 'str' and 'NoneType'"),
261+
(lambda: 42 < None, r"'<' .* of 'int' and 'types.NoneType'"),
262+
(lambda: None < 42, r"'<' .* of 'types.NoneType' and 'int'"),
263+
(lambda: 42 > None, r"'>' .* of 'int' and 'types.NoneType'"),
264+
(lambda: "foo" < None, r"'<' .* of 'str' and 'types.NoneType'"),
265265
(lambda: "foo" >= 666, r"'>=' .* of 'str' and 'int'"),
266-
(lambda: 42 <= None, r"'<=' .* of 'int' and 'NoneType'"),
267-
(lambda: 42 >= None, r"'>=' .* of 'int' and 'NoneType'"),
266+
(lambda: 42 <= None, r"'<=' .* of 'int' and 'types.NoneType'"),
267+
(lambda: 42 >= None, r"'>=' .* of 'int' and 'types.NoneType'"),
268268
(lambda: 42 < [], r"'<' .* of 'int' and 'list'"),
269269
(lambda: () > [], r"'>' .* of 'tuple' and 'list'"),
270-
(lambda: None >= None, r"'>=' .* of 'NoneType' and 'NoneType'"),
270+
(lambda: None >= None, r"'>=' .* of 'types.NoneType' and 'types.NoneType'"),
271271
(lambda: Spam() < 42, r"'<' .* of 'Spam' and 'int'"),
272272
(lambda: 42 < Spam(), r"'<' .* of 'int' and 'Spam'"),
273273
(lambda: Spam() <= Spam(), r"'<=' .* of 'Spam' and 'Spam'"),

Lib/test/test_socket.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ def testSendtoErrors(self):
910910
"a bytes-like object is required, not 'complex'")
911911
with self.assertRaises(TypeError) as cm:
912912
s.sendto(b'foo', None)
913-
self.assertIn('not NoneType',str(cm.exception))
913+
self.assertIn('not types.NoneType',str(cm.exception))
914914
# 3 args
915915
with self.assertRaises(TypeError) as cm:
916916
s.sendto('\u2620', 0, sockname)
@@ -922,7 +922,7 @@ def testSendtoErrors(self):
922922
"a bytes-like object is required, not 'complex'")
923923
with self.assertRaises(TypeError) as cm:
924924
s.sendto(b'foo', 0, None)
925-
self.assertIn('not NoneType', str(cm.exception))
925+
self.assertIn('not types.NoneType', str(cm.exception))
926926
with self.assertRaises(TypeError) as cm:
927927
s.sendto(b'foo', 'bar', sockname)
928928
with self.assertRaises(TypeError) as cm:

0 commit comments

Comments
 (0)