From 4f908e8a38699b2e6652d0e411b6b485910bdb3f Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 9 Dec 2022 10:45:07 +0200 Subject: [PATCH 1/7] gh-100129: Make the names of all classes in the types module resolvable --- Lib/test/test_complex.py | 2 +- Lib/test/test_coroutines.py | 6 +-- Lib/test/test_csv.py | 2 +- Lib/test/test_descr.py | 4 +- Lib/test/test_extcall.py | 42 +++++++++--------- Lib/test/test_funcattrs.py | 2 +- Lib/test/test_gdb.py | 8 ++-- Lib/test/test_generators.py | 34 +++++++------- Lib/test/test_genexps.py | 2 +- Lib/test/test_grammar.py | 4 +- Lib/test/test_json/test_fail.py | 2 +- Lib/test/test_richcmp.py | 14 +++--- Lib/test/test_socket.py | 4 +- Lib/test/test_traceback.py | 2 +- Lib/test/test_types.py | 4 +- Lib/test/test_typing.py | 2 +- Modules/_testcapimodule.c | 2 +- Objects/cellobject.c | 8 ++-- Objects/classobject.c | 18 ++++---- Objects/clinic/classobject.c.h | 20 ++++----- Objects/clinic/codeobject.c.h | 78 ++++++++++++++++----------------- Objects/codeobject.c | 49 +++++++++++---------- Objects/descrobject.c | 14 +++--- Objects/frameobject.c | 2 +- Objects/funcobject.c | 2 +- Objects/genobject.c | 6 +-- Objects/methodobject.c | 2 +- Objects/moduleobject.c | 2 +- Objects/object.c | 4 +- Objects/sliceobject.c | 2 +- Python/traceback.c | 2 +- Tools/gdb/libpython.py | 4 ++ 32 files changed, 176 insertions(+), 173 deletions(-) diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py index 51ba151505fb544..c9fa71849893623 100644 --- a/Lib/test/test_complex.py +++ b/Lib/test/test_complex.py @@ -395,7 +395,7 @@ def split_zeros(x): self.assertRaises(TypeError, float, 5+3j) self.assertRaises(ValueError, complex, "") self.assertRaises(TypeError, complex, None) - self.assertRaisesRegex(TypeError, "not 'NoneType'", complex, None) + self.assertRaisesRegex(TypeError, "not 'types.NoneType'", complex, None) self.assertRaises(ValueError, complex, "\0") self.assertRaises(ValueError, complex, "3\09") self.assertRaises(TypeError, complex, "1", "2") diff --git a/Lib/test/test_coroutines.py b/Lib/test/test_coroutines.py index 43a3ff0536fe283..b41ad399a06665f 100644 --- a/Lib/test/test_coroutines.py +++ b/Lib/test/test_coroutines.py @@ -565,7 +565,7 @@ async def foo(): coro = foo() check = lambda: self.assertRaisesRegex( - TypeError, "'coroutine' object is not iterable") + TypeError, r"'types\.CoroutineType' object is not iterable") with check(): list(coro) @@ -597,7 +597,7 @@ async def foo(): await bar() check = lambda: self.assertRaisesRegex( - TypeError, "'coroutine' object is not iterable") + TypeError, r"'types\.CoroutineType' object is not iterable") coro = foo() with check(): @@ -958,7 +958,7 @@ def test_corotype_1(self): self.assertIn('in coroutine', ct.throw.__doc__) self.assertIn('of the coroutine', ct.__dict__['__name__'].__doc__) self.assertIn('of the coroutine', ct.__dict__['__qualname__'].__doc__) - self.assertEqual(ct.__name__, 'coroutine') + self.assertEqual(ct.__name__, 'CoroutineType') async def f(): pass c = f() diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py index d64bff13a44e877..0b29d5db335eeea 100644 --- a/Lib/test/test_csv.py +++ b/Lib/test/test_csv.py @@ -1032,7 +1032,7 @@ class mydialect(csv.Dialect): with self.assertRaises(csv.Error) as cm: mydialect() self.assertEqual(str(cm.exception), - '"delimiter" must be string, not NoneType') + '"delimiter" must be string, not types.NoneType') def test_escapechar(self): class mydialect(csv.Dialect): diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index cbc020d1d3904aa..a50d692a90fbad2 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -4832,11 +4832,11 @@ class X: def test_qualname(self): descriptors = [str.lower, complex.real, float.real, int.__add__] - types = ['method', 'member', 'getset', 'wrapper'] + types = ['Method', 'Member', 'GetSet', 'Wrapper'] # make sure we have an example of each type of descriptor for d, n in zip(descriptors, types): - self.assertEqual(type(d).__name__, n + '_descriptor') + self.assertEqual(type(d).__name__, n + 'DescriptorType') for d in descriptors: qualname = d.__objclass__.__qualname__ + '.' + d.__name__ diff --git a/Lib/test/test_extcall.py b/Lib/test/test_extcall.py index d9d85fe79af883f..41dcaa76b25d2fe 100644 --- a/Lib/test/test_extcall.py +++ b/Lib/test/test_extcall.py @@ -263,73 +263,71 @@ ... TypeError: h() got an unexpected keyword argument 'e' - >>> h(*h) + >>> h(*1) Traceback (most recent call last): ... - TypeError: test.test_extcall.h() argument after * must be an iterable, not function + TypeError: test.test_extcall.h() argument after * must be an iterable, not int - >>> h(1, *h) + >>> h(1, *2) Traceback (most recent call last): ... - TypeError: Value after * must be an iterable, not function + TypeError: Value after * must be an iterable, not int - >>> h(*[1], *h) + >>> h(*[1], *2) Traceback (most recent call last): ... - TypeError: Value after * must be an iterable, not function + TypeError: Value after * must be an iterable, not int - >>> dir(*h) + >>> dir(*1) Traceback (most recent call last): ... - TypeError: dir() argument after * must be an iterable, not function + TypeError: dir() argument after * must be an iterable, not int >>> nothing = None - >>> nothing(*h) + >>> nothing(*1) Traceback (most recent call last): ... - TypeError: None argument after * must be an iterable, \ -not function + TypeError: None argument after * must be an iterable, not int - >>> h(**h) + >>> h(**1) Traceback (most recent call last): ... - TypeError: test.test_extcall.h() argument after ** must be a mapping, not function + TypeError: test.test_extcall.h() argument after ** must be a mapping, not int >>> h(**[]) Traceback (most recent call last): ... TypeError: test.test_extcall.h() argument after ** must be a mapping, not list - >>> h(a=1, **h) + >>> h(a=1, **2) Traceback (most recent call last): ... - TypeError: test.test_extcall.h() argument after ** must be a mapping, not function + TypeError: test.test_extcall.h() argument after ** must be a mapping, not int >>> h(a=1, **[]) Traceback (most recent call last): ... TypeError: test.test_extcall.h() argument after ** must be a mapping, not list - >>> h(**{'a': 1}, **h) + >>> h(**{'a': 1}, **2) Traceback (most recent call last): ... - TypeError: test.test_extcall.h() argument after ** must be a mapping, not function + TypeError: test.test_extcall.h() argument after ** must be a mapping, not int >>> h(**{'a': 1}, **[]) Traceback (most recent call last): ... TypeError: test.test_extcall.h() argument after ** must be a mapping, not list - >>> dir(**h) + >>> dir(**1) Traceback (most recent call last): ... - TypeError: dir() argument after ** must be a mapping, not function + TypeError: dir() argument after ** must be a mapping, not int - >>> nothing(**h) + >>> nothing(**1) Traceback (most recent call last): ... - TypeError: None argument after ** must be a mapping, \ -not function + TypeError: None argument after ** must be a mapping, not int >>> dir(b=1, **{'b': 1}) Traceback (most recent call last): diff --git a/Lib/test/test_funcattrs.py b/Lib/test/test_funcattrs.py index 77977d0ae966f8a..bde4e4dd62389e3 100644 --- a/Lib/test/test_funcattrs.py +++ b/Lib/test/test_funcattrs.py @@ -112,7 +112,7 @@ def f(): print(a) self.assertIsInstance(c, tuple) self.assertEqual(len(c), 1) # don't have a type object handy - self.assertEqual(c[0].__class__.__name__, "cell") + self.assertEqual(c[0].__class__.__name__, "CellType") self.cannot_set_attr(f, "__closure__", c, AttributeError) def test_cell_new(self): diff --git a/Lib/test/test_gdb.py b/Lib/test/test_gdb.py index 0f39b8f45714ad3..a652b7071abe82f 100644 --- a/Lib/test/test_gdb.py +++ b/Lib/test/test_gdb.py @@ -756,7 +756,7 @@ def test_pyup_command(self): self.assertMultilineMatches(bt, r'''^.* #[0-9]+ Frame 0x-?[0-9a-f]+, for file , line 12, in baz \(args=\(1, 2, 3\)\) -#[0-9]+ +#[0-9]+ $''') @unittest.skipUnless(HAS_PYUP_PYDOWN, "test requires py-up/py-down commands") @@ -785,7 +785,7 @@ def test_up_then_down(self): self.assertMultilineMatches(bt, r'''^.* #[0-9]+ Frame 0x-?[0-9a-f]+, for file , line 12, in baz \(args=\(1, 2, 3\)\) -#[0-9]+ +#[0-9]+ #[0-9]+ Frame 0x-?[0-9a-f]+, for file , line 12, in baz \(args=\(1, 2, 3\)\) $''') @@ -799,7 +799,7 @@ def test_bt(self): self.assertMultilineMatches(bt, r'''^.* Traceback \(most recent call first\): - + File ".*gdb_sample.py", line 10, in baz id\(42\) File ".*gdb_sample.py", line 7, in bar @@ -1014,7 +1014,7 @@ def test_printing_builtin(self): bt = self.get_stack_trace(script=self.get_sample_script(), cmds_after_breakpoint=['py-up', 'py-print len']) self.assertMultilineMatches(bt, - r".*\nbuiltin 'len' = \n.*") + r".*\nbuiltin 'len' = \n.*") class PyLocalsTests(DebuggerTests): @unittest.skipIf(python_is_optimized(), diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py index 492b77a954d865c..285bf5a018e4106 100644 --- a/Lib/test/test_generators.py +++ b/Lib/test/test_generators.py @@ -977,10 +977,10 @@ def b(): ... yield 1 ... >>> type(g) - + >>> i = g() >>> type(i) - + >>> [s for s in dir(i) if not s.startswith('_')] ['close', 'gi_code', 'gi_frame', 'gi_running', 'gi_suspended', 'gi_yieldfrom', 'send', 'throw'] >>> from test.support import HAVE_DOCSTRINGS @@ -997,11 +997,11 @@ def b(): >>> i.gi_running 0 >>> type(i.gi_frame) - + >>> i.gi_running = 42 Traceback (most recent call last): ... -AttributeError: attribute 'gi_running' of 'generator' objects is not writable +AttributeError: attribute 'gi_running' of 'types.GeneratorType' objects is not writable >>> def g(): ... yield me.gi_running >>> me = g() @@ -1372,27 +1372,27 @@ def b(): >>> def f(): ... yield >>> type(f()) - + >>> def f(): ... if 0: ... yield >>> type(f()) - + >>> def f(): ... if 0: ... yield 1 >>> type(f()) - + >>> def f(): ... if "": ... yield None >>> type(f()) - + >>> def f(): ... return @@ -1416,7 +1416,7 @@ def b(): ... x = 1 ... return >>> type(f()) - + >>> def f(): ... if 0: @@ -1424,7 +1424,7 @@ def b(): ... yield 1 ... >>> type(f()) - + >>> def f(): ... if 0: @@ -1434,7 +1434,7 @@ def b(): ... def f(self): ... yield 2 >>> type(f()) - + >>> def f(): ... if 0: @@ -1442,7 +1442,7 @@ def b(): ... if 0: ... yield 2 >>> type(f()) - + This one caused a crash (see SF bug 567538): @@ -2093,7 +2093,7 @@ def printsolution(self, x): >>> def f(): list(i for i in [(yield 26)]) >>> type(f()) - + A yield expression with augmented assignment. @@ -2364,21 +2364,21 @@ def printsolution(self, x): >>> def f(): x += yield >>> type(f()) - + >>> def f(): x = yield >>> type(f()) - + >>> def f(): lambda x=(yield): 1 >>> type(f()) - + >>> def f(d): d[(yield "a")] = d[(yield "b")] = 27 >>> data = [1,2] >>> g = f(data) >>> type(g) - + >>> g.send(None) 'a' >>> data diff --git a/Lib/test/test_genexps.py b/Lib/test/test_genexps.py index 4f2d3cdcc7943ea..2a7255d63830727 100644 --- a/Lib/test/test_genexps.py +++ b/Lib/test/test_genexps.py @@ -48,7 +48,7 @@ >>> g = (i*i for i in range(4)) >>> type(g) - + >>> list(g) [0, 1, 4, 9] diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py index 58f907eac09d53e..713e411f2d70404 100644 --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -1521,9 +1521,9 @@ def check(test): msg=r'indices must be integers or slices, not dict;' check('[[1, 2] [{3: 4}]]') check('[[1, 2] [{i: i for i in range(5)}]]') - msg=r'indices must be integers or slices, not generator;' + msg=r'indices must be integers or slices, not types\.GeneratorType;' check('[[1, 2] [(i for i in range(5))]]') - msg=r'indices must be integers or slices, not function;' + msg=r'indices must be integers or slices, not types\.FunctionType;' check('[[1, 2] [(lambda x, y: x)]]') msg=r'indices must be integers or slices, not str;' check('[[1, 2] [f"{x}"]]') diff --git a/Lib/test/test_json/test_fail.py b/Lib/test/test_json/test_fail.py index efc982e8b0eb04d..cdd5464396f6970 100644 --- a/Lib/test/test_json/test_fail.py +++ b/Lib/test/test_json/test_fail.py @@ -100,7 +100,7 @@ def test_non_string_keys_dict(self): def test_not_serializable(self): import sys with self.assertRaisesRegex(TypeError, - 'Object of type module is not JSON serializable'): + 'Object of type ModuleType is not JSON serializable'): self.dumps(sys) def test_truncated_input(self): diff --git a/Lib/test/test_richcmp.py b/Lib/test/test_richcmp.py index 58729a9fea62fa9..eaaceb50011e8d1 100644 --- a/Lib/test/test_richcmp.py +++ b/Lib/test/test_richcmp.py @@ -258,16 +258,16 @@ class Spam: pass tests = [ - (lambda: 42 < None, r"'<' .* of 'int' and 'NoneType'"), - (lambda: None < 42, r"'<' .* of 'NoneType' and 'int'"), - (lambda: 42 > None, r"'>' .* of 'int' and 'NoneType'"), - (lambda: "foo" < None, r"'<' .* of 'str' and 'NoneType'"), + (lambda: 42 < None, r"'<' .* of 'int' and 'types.NoneType'"), + (lambda: None < 42, r"'<' .* of 'types.NoneType' and 'int'"), + (lambda: 42 > None, r"'>' .* of 'int' and 'types.NoneType'"), + (lambda: "foo" < None, r"'<' .* of 'str' and 'types.NoneType'"), (lambda: "foo" >= 666, r"'>=' .* of 'str' and 'int'"), - (lambda: 42 <= None, r"'<=' .* of 'int' and 'NoneType'"), - (lambda: 42 >= None, r"'>=' .* of 'int' and 'NoneType'"), + (lambda: 42 <= None, r"'<=' .* of 'int' and 'types.NoneType'"), + (lambda: 42 >= None, r"'>=' .* of 'int' and 'types.NoneType'"), (lambda: 42 < [], r"'<' .* of 'int' and 'list'"), (lambda: () > [], r"'>' .* of 'tuple' and 'list'"), - (lambda: None >= None, r"'>=' .* of 'NoneType' and 'NoneType'"), + (lambda: None >= None, r"'>=' .* of 'types.NoneType' and 'types.NoneType'"), (lambda: Spam() < 42, r"'<' .* of 'Spam' and 'int'"), (lambda: 42 < Spam(), r"'<' .* of 'int' and 'Spam'"), (lambda: Spam() <= Spam(), r"'<=' .* of 'Spam' and 'Spam'"), diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index d808f3f62b96dca..5f0a330251f60df 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -910,7 +910,7 @@ def testSendtoErrors(self): "a bytes-like object is required, not 'complex'") with self.assertRaises(TypeError) as cm: s.sendto(b'foo', None) - self.assertIn('not NoneType',str(cm.exception)) + self.assertIn('not types.NoneType',str(cm.exception)) # 3 args with self.assertRaises(TypeError) as cm: s.sendto('\u2620', 0, sockname) @@ -922,7 +922,7 @@ def testSendtoErrors(self): "a bytes-like object is required, not 'complex'") with self.assertRaises(TypeError) as cm: s.sendto(b'foo', 0, None) - self.assertIn('not NoneType', str(cm.exception)) + self.assertIn('not types.NoneType', str(cm.exception)) with self.assertRaises(TypeError) as cm: s.sendto(b'foo', 'bar', sockname) with self.assertRaises(TypeError) as cm: diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 95b1bae4f60850b..0776d99adbc8431 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -345,7 +345,7 @@ def test_format_exception_only_exc(self): self.assertEqual(output, ["Exception: projector\n"]) def test_exception_is_None(self): - NONE_EXC_STRING = 'NoneType: None\n' + NONE_EXC_STRING = 'types.NoneType: None\n' excfile = StringIO() traceback.print_exception(None, file=excfile) self.assertEqual(excfile.getvalue(), NONE_EXC_STRING) diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index af095632a36fcb7..211b9e5761e4577 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -1388,7 +1388,7 @@ def __prepare__(*args): return None with self.assertRaisesRegex(TypeError, r'^BadMeta\.__prepare__\(\) must ' - r'return a mapping, not NoneType$'): + r'return a mapping, not types.NoneType$'): class Foo(metaclass=BadMeta): pass # Also test the case in which the metaclass is not a type. @@ -1398,7 +1398,7 @@ def __prepare__(*args): return None with self.assertRaisesRegex(TypeError, r'^\.__prepare__\(\) must ' - r'return a mapping, not NoneType$'): + r'return a mapping, not types.NoneType$'): class Bar(metaclass=BadMeta()): pass diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 1cae1b0de7140f6..ab28e12dc9086aa 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -1669,7 +1669,7 @@ def test_repr(self): u = Union[str, None] self.assertEqual(repr(u), 'typing.Optional[str]') u = Union[None, str, int] - self.assertEqual(repr(u), 'typing.Union[NoneType, str, int]') + self.assertEqual(repr(u), 'typing.Union[types.NoneType, str, int]') u = Optional[str] self.assertEqual(repr(u), 'typing.Optional[str]') diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 83eef73a875d9d5..fec5f68285ec647 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -629,7 +629,7 @@ test_get_type_name(PyObject *self, PyObject *Py_UNUSED(ignored)) Py_DECREF(tp_name); tp_name = PyType_GetName(&PyModule_Type); - assert(strcmp(PyUnicode_AsUTF8(tp_name), "module") == 0); + assert(strcmp(PyUnicode_AsUTF8(tp_name), "ModuleType") == 0); Py_DECREF(tp_name); PyObject *HeapTypeNameType = PyType_FromSpec(&HeapTypeNameType_Spec); diff --git a/Objects/cellobject.c b/Objects/cellobject.c index f516707f6f80869..1e9ee5c36359790 100644 --- a/Objects/cellobject.c +++ b/Objects/cellobject.c @@ -18,7 +18,7 @@ PyCell_New(PyObject *obj) } PyDoc_STRVAR(cell_new_doc, -"cell([contents])\n" +"types.CellType([contents])\n" "--\n" "\n" "Create a new cell object.\n" @@ -35,11 +35,11 @@ cell_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) PyObject *return_value = NULL; PyObject *obj = NULL; - if (!_PyArg_NoKeywords("cell", kwargs)) { + if (!_PyArg_NoKeywords("CellType", kwargs)) { goto exit; } /* min = 0: we allow the cell to be empty */ - if (!PyArg_UnpackTuple(args, "cell", 0, 1, &obj)) { + if (!PyArg_UnpackTuple(args, "CellType", 0, 1, &obj)) { goto exit; } return_value = PyCell_New(obj); @@ -151,7 +151,7 @@ static PyGetSetDef cell_getsetlist[] = { PyTypeObject PyCell_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "cell", + "types.CellType", sizeof(PyCellObject), 0, (destructor)cell_dealloc, /* tp_dealloc */ diff --git a/Objects/classobject.c b/Objects/classobject.c index 2cb192e725d40d0..caabfb766059b2a 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -12,9 +12,9 @@ #define TP_DESCR_GET(t) ((t)->tp_descr_get) /*[clinic input] -class method "PyMethodObject *" "&PyMethod_Type" +class MethodType "PyMethodObject *" "&PyMethod_Type" [clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=b16e47edf6107c23]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=23d815bbfe0db041]*/ PyObject * @@ -121,12 +121,12 @@ PyMethod_New(PyObject *func, PyObject *self) } /*[clinic input] -method.__reduce__ +MethodType.__reduce__ [clinic start generated code]*/ static PyObject * -method___reduce___impl(PyMethodObject *self) -/*[clinic end generated code: output=6c04506d0fa6fdcb input=143a0bf5e96de6e8]*/ +MethodType___reduce___impl(PyMethodObject *self) +/*[clinic end generated code: output=ce1c37b9022af4df input=c1b5dbc4739fccfb]*/ { PyObject *funcself = PyMethod_GET_SELF(self); PyObject *func = PyMethod_GET_FUNCTION(self); @@ -139,7 +139,7 @@ method___reduce___impl(PyMethodObject *self) } static PyMethodDef method_methods[] = { - METHOD___REDUCE___METHODDEF + METHODTYPE___REDUCE___METHODDEF {NULL, NULL} }; @@ -202,7 +202,7 @@ method_getattro(PyObject *obj, PyObject *name) /*[clinic input] @classmethod -method.__new__ as method_new +MethodType.__new__ as method_new function: object instance: object / @@ -212,7 +212,7 @@ Create a bound instance method object. static PyObject * method_new_impl(PyTypeObject *type, PyObject *function, PyObject *instance) -/*[clinic end generated code: output=d33ef4ebf702e1f7 input=4e32facc3c3108ae]*/ +/*[clinic end generated code: output=d33ef4ebf702e1f7 input=9e26d1b4a248c3c5]*/ { if (!PyCallable_Check(function)) { PyErr_SetString(PyExc_TypeError, @@ -318,7 +318,7 @@ method_traverse(PyMethodObject *im, visitproc visit, void *arg) PyTypeObject PyMethod_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - .tp_name = "method", + .tp_name = "types.MethodType", .tp_basicsize = sizeof(PyMethodObject), .tp_dealloc = (destructor)method_dealloc, .tp_vectorcall_offset = offsetof(PyMethodObject, vectorcall), diff --git a/Objects/clinic/classobject.c.h b/Objects/clinic/classobject.c.h index 6c449829662af3c..340f203d5082d2a 100644 --- a/Objects/clinic/classobject.c.h +++ b/Objects/clinic/classobject.c.h @@ -8,25 +8,25 @@ preserve #endif -PyDoc_STRVAR(method___reduce____doc__, +PyDoc_STRVAR(MethodType___reduce____doc__, "__reduce__($self, /)\n" "--\n" "\n"); -#define METHOD___REDUCE___METHODDEF \ - {"__reduce__", (PyCFunction)method___reduce__, METH_NOARGS, method___reduce____doc__}, +#define METHODTYPE___REDUCE___METHODDEF \ + {"__reduce__", (PyCFunction)MethodType___reduce__, METH_NOARGS, MethodType___reduce____doc__}, static PyObject * -method___reduce___impl(PyMethodObject *self); +MethodType___reduce___impl(PyMethodObject *self); static PyObject * -method___reduce__(PyMethodObject *self, PyObject *Py_UNUSED(ignored)) +MethodType___reduce__(PyMethodObject *self, PyObject *Py_UNUSED(ignored)) { - return method___reduce___impl(self); + return MethodType___reduce___impl(self); } PyDoc_STRVAR(method_new__doc__, -"method(function, instance, /)\n" +"MethodType(function, instance, /)\n" "--\n" "\n" "Create a bound instance method object."); @@ -43,10 +43,10 @@ method_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) if ((type == &PyMethod_Type || type->tp_init == PyMethod_Type.tp_init) && - !_PyArg_NoKeywords("method", kwargs)) { + !_PyArg_NoKeywords("MethodType", kwargs)) { goto exit; } - if (!_PyArg_CheckPositional("method", PyTuple_GET_SIZE(args), 2, 2)) { + if (!_PyArg_CheckPositional("MethodType", PyTuple_GET_SIZE(args), 2, 2)) { goto exit; } function = PyTuple_GET_ITEM(args, 0); @@ -86,4 +86,4 @@ instancemethod_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=e3294c26a71d456d input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b6a95b6c0ae95a3d input=a9049054013a1b77]*/ diff --git a/Objects/clinic/codeobject.c.h b/Objects/clinic/codeobject.c.h index da33f4a6a20c1b3..4f46f962b3856ec 100644 --- a/Objects/clinic/codeobject.c.h +++ b/Objects/clinic/codeobject.c.h @@ -9,10 +9,10 @@ preserve PyDoc_STRVAR(code_new__doc__, -"code(argcount, posonlyargcount, kwonlyargcount, nlocals, stacksize,\n" -" flags, codestring, constants, names, varnames, filename, name,\n" -" qualname, firstlineno, linetable, exceptiontable, freevars=(),\n" -" cellvars=(), /)\n" +"CodeType(argcount, posonlyargcount, kwonlyargcount, nlocals, stacksize,\n" +" flags, codestring, constants, names, varnames, filename, name,\n" +" qualname, firstlineno, linetable, exceptiontable, freevars=(),\n" +" cellvars=(), /)\n" "--\n" "\n" "Create a code object. Not for the faint of heart."); @@ -51,10 +51,10 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) if ((type == &PyCode_Type || type->tp_init == PyCode_Type.tp_init) && - !_PyArg_NoKeywords("code", kwargs)) { + !_PyArg_NoKeywords("CodeType", kwargs)) { goto exit; } - if (!_PyArg_CheckPositional("code", PyTuple_GET_SIZE(args), 16, 18)) { + if (!_PyArg_CheckPositional("CodeType", PyTuple_GET_SIZE(args), 16, 18)) { goto exit; } argcount = _PyLong_AsInt(PyTuple_GET_ITEM(args, 0)); @@ -82,27 +82,27 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) goto exit; } if (!PyBytes_Check(PyTuple_GET_ITEM(args, 6))) { - _PyArg_BadArgument("code", "argument 7", "bytes", PyTuple_GET_ITEM(args, 6)); + _PyArg_BadArgument("CodeType", "argument 7", "bytes", PyTuple_GET_ITEM(args, 6)); goto exit; } code = PyTuple_GET_ITEM(args, 6); if (!PyTuple_Check(PyTuple_GET_ITEM(args, 7))) { - _PyArg_BadArgument("code", "argument 8", "tuple", PyTuple_GET_ITEM(args, 7)); + _PyArg_BadArgument("CodeType", "argument 8", "tuple", PyTuple_GET_ITEM(args, 7)); goto exit; } consts = PyTuple_GET_ITEM(args, 7); if (!PyTuple_Check(PyTuple_GET_ITEM(args, 8))) { - _PyArg_BadArgument("code", "argument 9", "tuple", PyTuple_GET_ITEM(args, 8)); + _PyArg_BadArgument("CodeType", "argument 9", "tuple", PyTuple_GET_ITEM(args, 8)); goto exit; } names = PyTuple_GET_ITEM(args, 8); if (!PyTuple_Check(PyTuple_GET_ITEM(args, 9))) { - _PyArg_BadArgument("code", "argument 10", "tuple", PyTuple_GET_ITEM(args, 9)); + _PyArg_BadArgument("CodeType", "argument 10", "tuple", PyTuple_GET_ITEM(args, 9)); goto exit; } varnames = PyTuple_GET_ITEM(args, 9); if (!PyUnicode_Check(PyTuple_GET_ITEM(args, 10))) { - _PyArg_BadArgument("code", "argument 11", "str", PyTuple_GET_ITEM(args, 10)); + _PyArg_BadArgument("CodeType", "argument 11", "str", PyTuple_GET_ITEM(args, 10)); goto exit; } if (PyUnicode_READY(PyTuple_GET_ITEM(args, 10)) == -1) { @@ -110,7 +110,7 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) } filename = PyTuple_GET_ITEM(args, 10); if (!PyUnicode_Check(PyTuple_GET_ITEM(args, 11))) { - _PyArg_BadArgument("code", "argument 12", "str", PyTuple_GET_ITEM(args, 11)); + _PyArg_BadArgument("CodeType", "argument 12", "str", PyTuple_GET_ITEM(args, 11)); goto exit; } if (PyUnicode_READY(PyTuple_GET_ITEM(args, 11)) == -1) { @@ -118,7 +118,7 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) } name = PyTuple_GET_ITEM(args, 11); if (!PyUnicode_Check(PyTuple_GET_ITEM(args, 12))) { - _PyArg_BadArgument("code", "argument 13", "str", PyTuple_GET_ITEM(args, 12)); + _PyArg_BadArgument("CodeType", "argument 13", "str", PyTuple_GET_ITEM(args, 12)); goto exit; } if (PyUnicode_READY(PyTuple_GET_ITEM(args, 12)) == -1) { @@ -130,12 +130,12 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) goto exit; } if (!PyBytes_Check(PyTuple_GET_ITEM(args, 14))) { - _PyArg_BadArgument("code", "argument 15", "bytes", PyTuple_GET_ITEM(args, 14)); + _PyArg_BadArgument("CodeType", "argument 15", "bytes", PyTuple_GET_ITEM(args, 14)); goto exit; } linetable = PyTuple_GET_ITEM(args, 14); if (!PyBytes_Check(PyTuple_GET_ITEM(args, 15))) { - _PyArg_BadArgument("code", "argument 16", "bytes", PyTuple_GET_ITEM(args, 15)); + _PyArg_BadArgument("CodeType", "argument 16", "bytes", PyTuple_GET_ITEM(args, 15)); goto exit; } exceptiontable = PyTuple_GET_ITEM(args, 15); @@ -143,7 +143,7 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) goto skip_optional; } if (!PyTuple_Check(PyTuple_GET_ITEM(args, 16))) { - _PyArg_BadArgument("code", "argument 17", "tuple", PyTuple_GET_ITEM(args, 16)); + _PyArg_BadArgument("CodeType", "argument 17", "tuple", PyTuple_GET_ITEM(args, 16)); goto exit; } freevars = PyTuple_GET_ITEM(args, 16); @@ -151,7 +151,7 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) goto skip_optional; } if (!PyTuple_Check(PyTuple_GET_ITEM(args, 17))) { - _PyArg_BadArgument("code", "argument 18", "tuple", PyTuple_GET_ITEM(args, 17)); + _PyArg_BadArgument("CodeType", "argument 18", "tuple", PyTuple_GET_ITEM(args, 17)); goto exit; } cellvars = PyTuple_GET_ITEM(args, 17); @@ -162,7 +162,7 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) return return_value; } -PyDoc_STRVAR(code_replace__doc__, +PyDoc_STRVAR(types_CodeType_replace__doc__, "replace($self, /, *, co_argcount=-1, co_posonlyargcount=-1,\n" " co_kwonlyargcount=-1, co_nlocals=-1, co_stacksize=-1,\n" " co_flags=-1, co_firstlineno=-1, co_code=None, co_consts=None,\n" @@ -173,23 +173,23 @@ PyDoc_STRVAR(code_replace__doc__, "\n" "Return a copy of the code object with new values for the specified fields."); -#define CODE_REPLACE_METHODDEF \ - {"replace", _PyCFunction_CAST(code_replace), METH_FASTCALL|METH_KEYWORDS, code_replace__doc__}, +#define TYPES_CODETYPE_REPLACE_METHODDEF \ + {"replace", _PyCFunction_CAST(types_CodeType_replace), METH_FASTCALL|METH_KEYWORDS, types_CodeType_replace__doc__}, static PyObject * -code_replace_impl(PyCodeObject *self, int co_argcount, - int co_posonlyargcount, int co_kwonlyargcount, - int co_nlocals, int co_stacksize, int co_flags, - int co_firstlineno, PyBytesObject *co_code, - PyObject *co_consts, PyObject *co_names, - PyObject *co_varnames, PyObject *co_freevars, - PyObject *co_cellvars, PyObject *co_filename, - PyObject *co_name, PyObject *co_qualname, - PyBytesObject *co_linetable, - PyBytesObject *co_exceptiontable); +types_CodeType_replace_impl(PyCodeObject *self, int co_argcount, + int co_posonlyargcount, int co_kwonlyargcount, + int co_nlocals, int co_stacksize, int co_flags, + int co_firstlineno, PyBytesObject *co_code, + PyObject *co_consts, PyObject *co_names, + PyObject *co_varnames, PyObject *co_freevars, + PyObject *co_cellvars, PyObject *co_filename, + PyObject *co_name, PyObject *co_qualname, + PyBytesObject *co_linetable, + PyBytesObject *co_exceptiontable); static PyObject * -code_replace(PyCodeObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +types_CodeType_replace(PyCodeObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -423,13 +423,13 @@ code_replace(PyCodeObject *self, PyObject *const *args, Py_ssize_t nargs, PyObje } co_exceptiontable = (PyBytesObject *)args[17]; skip_optional_kwonly: - return_value = code_replace_impl(self, co_argcount, co_posonlyargcount, co_kwonlyargcount, co_nlocals, co_stacksize, co_flags, co_firstlineno, co_code, co_consts, co_names, co_varnames, co_freevars, co_cellvars, co_filename, co_name, co_qualname, co_linetable, co_exceptiontable); + return_value = types_CodeType_replace_impl(self, co_argcount, co_posonlyargcount, co_kwonlyargcount, co_nlocals, co_stacksize, co_flags, co_firstlineno, co_code, co_consts, co_names, co_varnames, co_freevars, co_cellvars, co_filename, co_name, co_qualname, co_linetable, co_exceptiontable); exit: return return_value; } -PyDoc_STRVAR(code__varname_from_oparg__doc__, +PyDoc_STRVAR(types_CodeType__varname_from_oparg__doc__, "_varname_from_oparg($self, /, oparg)\n" "--\n" "\n" @@ -437,14 +437,14 @@ PyDoc_STRVAR(code__varname_from_oparg__doc__, "\n" "WARNING: this method is for internal use only and may change or go away."); -#define CODE__VARNAME_FROM_OPARG_METHODDEF \ - {"_varname_from_oparg", _PyCFunction_CAST(code__varname_from_oparg), METH_FASTCALL|METH_KEYWORDS, code__varname_from_oparg__doc__}, +#define TYPES_CODETYPE__VARNAME_FROM_OPARG_METHODDEF \ + {"_varname_from_oparg", _PyCFunction_CAST(types_CodeType__varname_from_oparg), METH_FASTCALL|METH_KEYWORDS, types_CodeType__varname_from_oparg__doc__}, static PyObject * -code__varname_from_oparg_impl(PyCodeObject *self, int oparg); +types_CodeType__varname_from_oparg_impl(PyCodeObject *self, int oparg); static PyObject * -code__varname_from_oparg(PyCodeObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +types_CodeType__varname_from_oparg(PyCodeObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -483,9 +483,9 @@ code__varname_from_oparg(PyCodeObject *self, PyObject *const *args, Py_ssize_t n if (oparg == -1 && PyErr_Occurred()) { goto exit; } - return_value = code__varname_from_oparg_impl(self, oparg); + return_value = types_CodeType__varname_from_oparg_impl(self, oparg); exit: return return_value; } -/*[clinic end generated code: output=b6c98f17c60ace53 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=e2540ad099c750c9 input=a9049054013a1b77]*/ diff --git a/Objects/codeobject.c b/Objects/codeobject.c index 0c197d767b0a237..904826a66a5fc1a 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -1556,13 +1556,14 @@ PyCode_GetCode(PyCodeObject *co) ******************/ /*[clinic input] -class code "PyCodeObject *" "&PyCode_Type" +module types +class types.CodeType "PyCodeObject *" "&PyCode_Type" [clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=78aa5d576683bb4b]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=5bdfe35a3b23672e]*/ /*[clinic input] @classmethod -code.__new__ as code_new +types.CodeType.__new__ as code_new argcount: int posonlyargcount: int @@ -1595,7 +1596,7 @@ code_new_impl(PyTypeObject *type, int argcount, int posonlyargcount, PyObject *qualname, int firstlineno, PyObject *linetable, PyObject *exceptiontable, PyObject *freevars, PyObject *cellvars) -/*[clinic end generated code: output=069fa20d299f9dda input=e31da3c41ad8064a]*/ +/*[clinic end generated code: output=069fa20d299f9dda input=bb23c6787f447b63]*/ { PyObject *co = NULL; PyObject *ournames = NULL; @@ -1603,7 +1604,7 @@ code_new_impl(PyTypeObject *type, int argcount, int posonlyargcount, PyObject *ourfreevars = NULL; PyObject *ourcellvars = NULL; - if (PySys_Audit("code.__new__", "OOOiiiiii", + if (PySys_Audit("types.CodeType.__new__", "OOOiiiiii", code, filename, name, argcount, posonlyargcount, kwonlyargcount, nlocals, stacksize, flags) < 0) { goto cleanup; @@ -1946,7 +1947,7 @@ code_linesiterator(PyCodeObject *code, PyObject *Py_UNUSED(args)) } /*[clinic input] -code.replace +types.CodeType.replace * co_argcount: int(c_default="self->co_argcount") = -1 @@ -1972,17 +1973,17 @@ Return a copy of the code object with new values for the specified fields. [clinic start generated code]*/ static PyObject * -code_replace_impl(PyCodeObject *self, int co_argcount, - int co_posonlyargcount, int co_kwonlyargcount, - int co_nlocals, int co_stacksize, int co_flags, - int co_firstlineno, PyBytesObject *co_code, - PyObject *co_consts, PyObject *co_names, - PyObject *co_varnames, PyObject *co_freevars, - PyObject *co_cellvars, PyObject *co_filename, - PyObject *co_name, PyObject *co_qualname, - PyBytesObject *co_linetable, - PyBytesObject *co_exceptiontable) -/*[clinic end generated code: output=b6cd9988391d5711 input=f6f68e03571f8d7c]*/ +types_CodeType_replace_impl(PyCodeObject *self, int co_argcount, + int co_posonlyargcount, int co_kwonlyargcount, + int co_nlocals, int co_stacksize, int co_flags, + int co_firstlineno, PyBytesObject *co_code, + PyObject *co_consts, PyObject *co_names, + PyObject *co_varnames, PyObject *co_freevars, + PyObject *co_cellvars, PyObject *co_filename, + PyObject *co_name, PyObject *co_qualname, + PyBytesObject *co_linetable, + PyBytesObject *co_exceptiontable) +/*[clinic end generated code: output=476976595896e057 input=71d4a98105cab87b]*/ { #define CHECK_INT_ARG(ARG) \ if (ARG < 0) { \ @@ -2010,7 +2011,7 @@ code_replace_impl(PyCodeObject *self, int co_argcount, co_code = (PyBytesObject *)code; } - if (PySys_Audit("code.__new__", "OOOiiiiii", + if (PySys_Audit("types.CodeType.__new__", "OOOiiiiii", co_code, co_filename, co_name, co_argcount, co_posonlyargcount, co_kwonlyargcount, co_nlocals, co_stacksize, co_flags) < 0) { @@ -2059,7 +2060,7 @@ code_replace_impl(PyCodeObject *self, int co_argcount, } /*[clinic input] -code._varname_from_oparg +types.CodeType._varname_from_oparg oparg: int @@ -2069,8 +2070,8 @@ WARNING: this method is for internal use only and may change or go away. [clinic start generated code]*/ static PyObject * -code__varname_from_oparg_impl(PyCodeObject *self, int oparg) -/*[clinic end generated code: output=1fd1130413184206 input=c5fa3ee9bac7d4ca]*/ +types_CodeType__varname_from_oparg_impl(PyCodeObject *self, int oparg) +/*[clinic end generated code: output=92172b43d4b576c0 input=bd29af426db28423]*/ { PyObject *name = PyTuple_GetItem(self->co_localsplusnames, oparg); if (name == NULL) { @@ -2085,15 +2086,15 @@ static struct PyMethodDef code_methods[] = { {"__sizeof__", (PyCFunction)code_sizeof, METH_NOARGS}, {"co_lines", (PyCFunction)code_linesiterator, METH_NOARGS}, {"co_positions", (PyCFunction)code_positionsiterator, METH_NOARGS}, - CODE_REPLACE_METHODDEF - CODE__VARNAME_FROM_OPARG_METHODDEF + TYPES_CODETYPE_REPLACE_METHODDEF + TYPES_CODETYPE__VARNAME_FROM_OPARG_METHODDEF {NULL, NULL} /* sentinel */ }; PyTypeObject PyCode_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "code", + "types.CodeType", offsetof(PyCodeObject, co_code_adaptive), sizeof(_Py_CODEUNIT), (destructor)code_dealloc, /* tp_dealloc */ diff --git a/Objects/descrobject.c b/Objects/descrobject.c index c545b90c6283e11..25d0424ae0843c3 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -709,7 +709,7 @@ descr_traverse(PyObject *self, visitproc visit, void *arg) PyTypeObject PyMethodDescr_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "method_descriptor", + "types.MethodDescriptorType", sizeof(PyMethodDescrObject), 0, (destructor)descr_dealloc, /* tp_dealloc */ @@ -749,7 +749,7 @@ PyTypeObject PyMethodDescr_Type = { /* This is for METH_CLASS in C, not for "f = classmethod(f)" in Python! */ PyTypeObject PyClassMethodDescr_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "classmethod_descriptor", + "types.ClassMethodDescriptorType", sizeof(PyMethodDescrObject), 0, (destructor)descr_dealloc, /* tp_dealloc */ @@ -786,7 +786,7 @@ PyTypeObject PyClassMethodDescr_Type = { PyTypeObject PyMemberDescr_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "member_descriptor", + "types.MemberDescriptorType", sizeof(PyMemberDescrObject), 0, (destructor)descr_dealloc, /* tp_dealloc */ @@ -823,7 +823,7 @@ PyTypeObject PyMemberDescr_Type = { PyTypeObject PyGetSetDescr_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "getset_descriptor", + "types.GetSetDescriptorType", sizeof(PyGetSetDescrObject), 0, (destructor)descr_dealloc, /* tp_dealloc */ @@ -860,7 +860,7 @@ PyTypeObject PyGetSetDescr_Type = { PyTypeObject PyWrapperDescr_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "wrapper_descriptor", + "types.WrapperDescriptorType", sizeof(PyWrapperDescrObject), 0, (destructor)descr_dealloc, /* tp_dealloc */ @@ -1411,7 +1411,7 @@ wrapper_traverse(PyObject *self, visitproc visit, void *arg) PyTypeObject _PyMethodWrapper_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "method-wrapper", /* tp_name */ + "types.MethodWrapperType", /* tp_name */ sizeof(wrapperobject), /* tp_basicsize */ 0, /* tp_itemsize */ /* methods */ @@ -1877,7 +1877,7 @@ property_clear(PyObject *self) PyTypeObject PyDictProxy_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "mappingproxy", /* tp_name */ + "types.MappingProxyType", /* tp_name */ sizeof(mappingproxyobject), /* tp_basicsize */ 0, /* tp_itemsize */ /* methods */ diff --git a/Objects/frameobject.c b/Objects/frameobject.c index 74c26d8d4d96a5e..90b7897880a150c 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -973,7 +973,7 @@ static PyMethodDef frame_methods[] = { PyTypeObject PyFrame_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "frame", + "types.FrameType", offsetof(PyFrameObject, _f_frame_data) + offsetof(_PyInterpreterFrame, localsplus), sizeof(PyObject *), diff --git a/Objects/funcobject.c b/Objects/funcobject.c index bf97edc53ad7d97..92ba37db4afd48b 100644 --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -804,7 +804,7 @@ func_descr_get(PyObject *func, PyObject *obj, PyObject *type) PyTypeObject PyFunction_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "function", + "types.FunctionType", sizeof(PyFunctionObject), 0, (destructor)func_dealloc, /* tp_dealloc */ diff --git a/Objects/genobject.c b/Objects/genobject.c index c006f1af2177f94..a620fba5ad046f8 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -794,7 +794,7 @@ static PyAsyncMethods gen_as_async = { PyTypeObject PyGen_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "generator", /* tp_name */ + "types.GeneratorType", /* tp_name */ offsetof(PyGenObject, gi_iframe) + offsetof(_PyInterpreterFrame, localsplus), /* tp_basicsize */ sizeof(PyObject *), /* tp_itemsize */ @@ -1139,7 +1139,7 @@ static PyAsyncMethods coro_as_async = { PyTypeObject PyCoro_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "coroutine", /* tp_name */ + "types.CoroutineType", /* tp_name */ offsetof(PyCoroObject, cr_iframe) + offsetof(_PyInterpreterFrame, localsplus), /* tp_basicsize */ sizeof(PyObject *), /* tp_itemsize */ @@ -1542,7 +1542,7 @@ static PyAsyncMethods async_gen_as_async = { PyTypeObject PyAsyncGen_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "async_generator", /* tp_name */ + "types.AsyncGeneratorType", /* tp_name */ offsetof(PyAsyncGenObject, ag_iframe) + offsetof(_PyInterpreterFrame, localsplus), /* tp_basicsize */ sizeof(PyObject *), /* tp_itemsize */ diff --git a/Objects/methodobject.c b/Objects/methodobject.c index 51752dec3dd08c3..518fd80d1d7841c 100644 --- a/Objects/methodobject.c +++ b/Objects/methodobject.c @@ -328,7 +328,7 @@ meth_hash(PyCFunctionObject *a) PyTypeObject PyCFunction_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "builtin_function_or_method", + "types.BuiltinFunctionType", sizeof(PyCFunctionObject), 0, (destructor)meth_dealloc, /* tp_dealloc */ diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index 8e03f2446f6fcd0..deb274067210643 100644 --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -954,7 +954,7 @@ static PyGetSetDef module_getsets[] = { PyTypeObject PyModule_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "module", /* tp_name */ + "types.ModuleType", /* tp_name */ sizeof(PyModuleObject), /* tp_basicsize */ 0, /* tp_itemsize */ (destructor)module_dealloc, /* tp_dealloc */ diff --git a/Objects/object.c b/Objects/object.c index 687bd36d2b4af1e..cd8555dfd73fefc 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -1680,7 +1680,7 @@ static PyNumberMethods none_as_number = { PyTypeObject _PyNone_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "NoneType", + "types.NoneType", 0, 0, none_dealloc, /*tp_dealloc*/ /*never called*/ @@ -1781,7 +1781,7 @@ static PyNumberMethods notimplemented_as_number = { PyTypeObject _PyNotImplemented_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "NotImplementedType", + "types.NotImplementedType", 0, 0, notimplemented_dealloc, /*tp_dealloc*/ /*never called*/ diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c index 5694bd9c661fa53..86a3488c9378753 100644 --- a/Objects/sliceobject.c +++ b/Objects/sliceobject.c @@ -48,7 +48,7 @@ static PyMethodDef ellipsis_methods[] = { PyTypeObject PyEllipsis_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "ellipsis", /* tp_name */ + "types.EllipsisType", /* tp_name */ 0, /* tp_basicsize */ 0, /* tp_itemsize */ 0, /*never called*/ /* tp_dealloc */ diff --git a/Python/traceback.c b/Python/traceback.c index da26c9b260a3bd9..9a0c5856abce497 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -188,7 +188,7 @@ tb_clear(PyTracebackObject *tb) PyTypeObject PyTraceBack_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "traceback", + "types.TracebackType", sizeof(PyTracebackObject), 0, (destructor)tb_dealloc, /*tp_dealloc*/ diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py index c003c1ab4a23bd9..126ff403f4eeea0 100755 --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -345,11 +345,15 @@ def subclass_from_type(cls, t): name_map = {'bool': PyBoolObjectPtr, 'classobj': PyClassObjectPtr, 'NoneType': PyNoneStructPtr, + 'types.NoneType': PyNoneStructPtr, 'frame': PyFrameObjectPtr, + 'types.FrameType': PyFrameObjectPtr, 'set' : PySetObjectPtr, 'frozenset' : PySetObjectPtr, 'builtin_function_or_method' : PyCFunctionObjectPtr, + 'types.BuiltinFunctionType' : PyCFunctionObjectPtr, 'method-wrapper': wrapperobject, + 'types.MethodWrapperType': wrapperobject, } if tp_name in name_map: return name_map[tp_name] From 6cd302c52a68620681c80e18ef9f6eafee8489a4 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 9 Dec 2022 19:31:08 +0200 Subject: [PATCH 2/7] Add tests. --- Lib/test/pickletester.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index 499f80a15f34227..7aade8c8554d186 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -1,3 +1,4 @@ +import builtins import collections import copyreg import dbm @@ -11,6 +12,7 @@ import struct import sys import threading +import types import unittest import weakref from textwrap import dedent @@ -1980,6 +1982,40 @@ def test_singleton_types(self): u = self.loads(s) self.assertIs(type(singleton), u) + def test_builtin_types(self): + for t in builtins.__dict__.values(): + if isinstance(t, type) and not issubclass(t, BaseException): + for proto in protocols: + s = self.dumps(t, proto) + self.assertIs(self.loads(s), t) + + def test_types_types(self): + for t in types.__dict__.values(): + if isinstance(t, type): + for proto in protocols: + s = self.dumps(t, proto) + self.assertIs(self.loads(s), t) + + def test_builtin_exceptions(self): + for t in builtins.__dict__.values(): + if isinstance(t, type) and issubclass(t, BaseException): + for proto in protocols: + s = self.dumps(t, proto) + u = self.loads(s) + if proto <= 2 and issubclass(t, OSError) and t is not BlockingIOError: + self.assertIs(u, OSError) + elif proto <= 2 and issubclass(t, ImportError): + self.assertIs(u, ImportError) + else: + self.assertIs(u, t) + + def test_builtin_functions(self): + for t in builtins.__dict__.values(): + if isinstance(t, types.BuiltinFunctionType): + for proto in protocols: + s = self.dumps(t, proto) + self.assertIs(self.loads(s), t) + # Tests for protocol 2 def test_proto(self): From 5da1f0b3def4c3123b4b5b977cf28bc13232bf94 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 9 Dec 2022 19:35:38 +0200 Subject: [PATCH 3/7] Add a NEWS entry. --- .../2022-12-09-19-35-34.gh-issue-100129.Pb9_RV.rst | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-12-09-19-35-34.gh-issue-100129.Pb9_RV.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-12-09-19-35-34.gh-issue-100129.Pb9_RV.rst b/Misc/NEWS.d/next/Core and Builtins/2022-12-09-19-35-34.gh-issue-100129.Pb9_RV.rst new file mode 100644 index 000000000000000..e403d5103085942 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-12-09-19-35-34.gh-issue-100129.Pb9_RV.rst @@ -0,0 +1,4 @@ +All builtin types exposed in the :mod:`types` module now have attributes +``__module__``, ``__qualname__`` and ``__name__`` which allow to resolve +them in the corresponding module. As result, all these types (but not +neccessary their instances) are now pickleable. From 29ef7e646e85377ef7bf81f0f7bf7469284f2749 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 9 Dec 2022 20:02:24 +0200 Subject: [PATCH 4/7] Fix doctests. --- Doc/library/functools.rst | 2 +- Doc/library/multiprocessing.rst | 6 +++--- Doc/library/multiprocessing.shared_memory.rst | 2 +- Doc/library/unittest.mock.rst | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Doc/library/functools.rst b/Doc/library/functools.rst index 2f0a9bd8be88155..d5ad1bfdf729f43 100644 --- a/Doc/library/functools.rst +++ b/Doc/library/functools.rst @@ -548,7 +548,7 @@ The :mod:`functools` module defines the following functions: attribute:: >>> fun.registry.keys() - dict_keys([, , , + dict_keys([, , , , , ]) >>> fun.registry[float] diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst index b5ceeb796f8f2f2..efe26eab037343c 100644 --- a/Doc/library/multiprocessing.rst +++ b/Doc/library/multiprocessing.rst @@ -460,9 +460,9 @@ process which created it. Traceback (most recent call last): Traceback (most recent call last): Traceback (most recent call last): - AttributeError: 'module' object has no attribute 'f' - AttributeError: 'module' object has no attribute 'f' - AttributeError: 'module' object has no attribute 'f' + AttributeError: 'types.ModuleType' object has no attribute 'f' + AttributeError: 'types.ModuleType' object has no attribute 'f' + AttributeError: 'types.ModuleType' object has no attribute 'f' (If you try this it will actually output three full tracebacks interleaved in a semi-random fashion, and then you may have to diff --git a/Doc/library/multiprocessing.shared_memory.rst b/Doc/library/multiprocessing.shared_memory.rst index 76046b34610abef..56684a129cf0292 100644 --- a/Doc/library/multiprocessing.shared_memory.rst +++ b/Doc/library/multiprocessing.shared_memory.rst @@ -300,7 +300,7 @@ instance: >>> from multiprocessing import shared_memory >>> a = shared_memory.ShareableList(['howdy', b'HoWdY', -273.154, 100, None, True, 42]) >>> [ type(entry) for entry in a ] - [, , , , , , ] + [, , , , , , ] >>> a[2] -273.154 >>> a[2] = -78.5 diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst index b768557e6075f6e..9e67dcab2b7d084 100644 --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -890,7 +890,7 @@ object:: ... >>> mock = MagicMock(async_func) >>> mock - + >>> mock() # doctest: +SKIP From fd01d7ad3c3737f0e79b07e6d29681ff07b18111 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 21 Dec 2022 17:00:54 +0200 Subject: [PATCH 5/7] Revert changes made in other issue. --- Doc/library/multiprocessing.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/multiprocessing.rst b/Doc/library/multiprocessing.rst index efe26eab037343c..b5ceeb796f8f2f2 100644 --- a/Doc/library/multiprocessing.rst +++ b/Doc/library/multiprocessing.rst @@ -460,9 +460,9 @@ process which created it. Traceback (most recent call last): Traceback (most recent call last): Traceback (most recent call last): - AttributeError: 'types.ModuleType' object has no attribute 'f' - AttributeError: 'types.ModuleType' object has no attribute 'f' - AttributeError: 'types.ModuleType' object has no attribute 'f' + AttributeError: 'module' object has no attribute 'f' + AttributeError: 'module' object has no attribute 'f' + AttributeError: 'module' object has no attribute 'f' (If you try this it will actually output three full tracebacks interleaved in a semi-random fashion, and then you may have to From f74b4b2f146d8230ffb3967ae16101904b8e076b Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 4 Jun 2026 16:30:51 +0300 Subject: [PATCH 6/7] Fix new type names and new tests. --- Lib/_pyrepl/fancycompleter.py | 7 ++ Lib/json/encoder.py | 14 ++- Lib/test/pickletester.py | 30 ++++- Lib/test/test_call.py | 10 +- Lib/test/test_crossinterp.py | 12 +- Lib/test/test_exception_group.py | 2 +- Lib/test/test_frame.py | 2 +- Lib/test/test_gdb/test_backtrace.py | 2 +- Lib/test/test_import/__init__.py | 2 +- Lib/test/test_json/test_default.py | 4 +- Lib/test/test_lazy_import/__init__.py | 8 +- Lib/test/test_ordered_dict.py | 2 +- Lib/test/test_pdb.py | 2 +- Lib/test/test_pydoc/test_pydoc.py | 2 +- Lib/test/test_types.py | 7 +- Lib/test/test_unittest/test_async_case.py | 2 +- Lib/test/test_unittest/test_case.py | 4 +- Lib/test/test_unpack_ex.py | 2 +- Lib/test/test_warnings/__init__.py | 2 +- Objects/capsule.c | 2 +- Objects/cellobject.c | 2 +- Objects/clinic/descrobject.c.h | 6 +- Objects/clinic/funcobject.c.h | 147 +++++++++++----------- Objects/clinic/moduleobject.c.h | 8 +- Objects/descrobject.c | 9 +- Objects/frameobject.c | 4 +- Objects/funcobject.c | 54 ++++---- Objects/lazyimportobject.c | 4 +- Objects/moduleobject.c | 9 +- Objects/sliceobject.c | 2 +- Python/clinic/traceback.c.h | 45 +++---- Python/traceback.c | 24 ++-- 32 files changed, 239 insertions(+), 193 deletions(-) diff --git a/Lib/_pyrepl/fancycompleter.py b/Lib/_pyrepl/fancycompleter.py index ac4f0afdbc721c3..d2afd7e1e00a773 100644 --- a/Lib/_pyrepl/fancycompleter.py +++ b/Lib/_pyrepl/fancycompleter.py @@ -8,6 +8,7 @@ from _colorize import ANSIColors, get_colors, get_theme import rlcompleter import keyword +import re import types TYPE_CHECKING = False @@ -43,6 +44,12 @@ def _color_for_obj(name: str, value: Any, theme: Theme) -> str: def _color_by_type(t, theme): typename = t.__name__ + if t.__module__ == 'types' and typename.endswith('Type'): + # MethodWrapperType -> method_wrapper + # 1. Remove the "Type" suffix. + # 2. Insert "_" before each upper letter in the middle. + # 3. Convert to lower case. + typename = re.sub(r'(? encoder for Python data structures. @@ -316,7 +324,7 @@ def _iterencode_list(lst, _current_indent_level): except GeneratorExit: raise except BaseException as exc: - exc.add_note(f'when serializing {type(lst).__name__} item {i}') + exc.add_note(f'when serializing {_T(lst)} item {i}') raise if newline_indent is not None: _current_indent_level -= 1 @@ -403,7 +411,7 @@ def _iterencode_dict(dct, _current_indent_level): except GeneratorExit: raise except BaseException as exc: - exc.add_note(f'when serializing {type(dct).__name__} item {key!r}') + exc.add_note(f'when serializing {_T(dct)} item {key!r}') raise if not first and newline_indent is not None: _current_indent_level -= 1 @@ -443,7 +451,7 @@ def _iterencode(o, _current_indent_level): except GeneratorExit: raise except BaseException as exc: - exc.add_note(f'when serializing {type(o).__name__} object') + exc.add_note(f'when serializing {_T(o)} object') raise if markers is not None: del markers[markerid] diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index dc2917ec51afb45..ee9a6ae47c4fb1a 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -1340,7 +1340,7 @@ def test_find_class(self): r"Can't resolve path 'log\.spam' on module 'math'") as cm: unpickler4.find_class('math', 'log.spam') self.assertEqual(str(cm.exception.__context__), - "'builtin_function_or_method' object has no attribute 'spam'") + "'types.BuiltinFunctionType' object has no attribute 'spam'") with self.assertRaisesRegex(AttributeError, r"module 'math' has no attribute 'log\.\.spam'"): unpickler.find_class('math', 'log..spam') @@ -1348,7 +1348,7 @@ def test_find_class(self): r"Can't resolve path 'log\.\.spam' on module 'math'") as cm: unpickler4.find_class('math', 'log..spam') self.assertEqual(str(cm.exception.__context__), - "'builtin_function_or_method' object has no attribute ''") + "'types.BuiltinFunctionType' object has no attribute ''") with self.assertRaisesRegex(AttributeError, "module 'math' has no attribute ''"): unpickler.find_class('math', '') @@ -3301,11 +3301,33 @@ def test_builtin_types(self): self.assertIs(self.loads(s), t) def test_types_types(self): + if self.py_version < (3, 8): + self.skipTest('not supported in Python < 3.8') + # types with __module__ == 'types' added before 3.16 + old_names = { + 'EllipsisType': (3, 8), + 'GenericAlias': (3, 9), + 'NoneType': (3, 8), + 'NotImplementedType': (3, 8), + 'SimpleNamespace': (3, 8), + 'Union': (3, 8), + 'DynamicClassAttribute': (3, 8), + '_GeneratorWrapper': (3, 8), + } + # new types added after 3.16 + new_names = { + } for t in types.__dict__.values(): if isinstance(t, type): + if self.py_version < (3, 16): + if t.__name__ not in old_names or self.py_version < old_names[t.__name__]: + continue + elif t.__name__ in new_names and self.py_version < new_names[t.__name__]: + continue for proto in protocols: - s = self.dumps(t, proto) - self.assertIs(self.loads(s), t) + with self.subTest(name=t.__name__, proto=proto): + s = self.dumps(t, proto) + self.assertIs(self.loads(s), t) def test_builtin_exceptions(self): new_names = { diff --git a/Lib/test/test_call.py b/Lib/test/test_call.py index f42526aee194174..d6015520859a062 100644 --- a/Lib/test/test_call.py +++ b/Lib/test/test_call.py @@ -227,29 +227,29 @@ def test_object_not_callable(self): self.assertRaisesRegex(TypeError, msg, object()) def test_module_not_callable_no_suggestion_0(self): - msg = r"^'module' object is not callable$" + msg = r"^'types\.ModuleType' object is not callable$" self.assertRaisesRegex(TypeError, msg, types.ModuleType("mod")) def test_module_not_callable_no_suggestion_1(self): - msg = r"^'module' object is not callable$" + msg = r"^'types\.ModuleType' object is not callable$" mod = types.ModuleType("mod") mod.mod = 42 self.assertRaisesRegex(TypeError, msg, mod) def test_module_not_callable_no_suggestion_2(self): - msg = r"^'module' object is not callable$" + msg = r"^'types\.ModuleType' object is not callable$" mod = types.ModuleType("mod") del mod.__name__ self.assertRaisesRegex(TypeError, msg, mod) def test_module_not_callable_no_suggestion_3(self): - msg = r"^'module' object is not callable$" + msg = r"^'types\.ModuleType' object is not callable$" mod = types.ModuleType("mod") mod.__name__ = 42 self.assertRaisesRegex(TypeError, msg, mod) def test_module_not_callable_suggestion(self): - msg = r"^'module' object is not callable\. Did you mean: 'mod\.mod\(\.\.\.\)'\?$" + msg = r"^'types\.ModuleType' object is not callable\. Did you mean: 'mod\.mod\(\.\.\.\)'\?$" mod = types.ModuleType("mod") mod.mod = lambda: ... self.assertRaisesRegex(TypeError, msg, mod) diff --git a/Lib/test/test_crossinterp.py b/Lib/test/test_crossinterp.py index f4bf5a66ad21550..941cad66c634880 100644 --- a/Lib/test/test_crossinterp.py +++ b/Lib/test/test_crossinterp.py @@ -61,6 +61,7 @@ def ignore_byteswarning(): METHOD = defs.SpamOkay().okay BUILTIN_METHOD = [].append +MEMBER_DESCRIPTOR = types.FunctionType.__globals__ METHOD_DESCRIPTOR_WRAPPER = str.join METHOD_WRAPPER = object().__str__ WRAPPER_DESCRIPTOR = object.__init__ @@ -69,7 +70,7 @@ def ignore_byteswarning(): BUILTIN_METHOD: types.BuiltinMethodType, dict.__dict__['fromkeys']: types.ClassMethodDescriptorType, types.FunctionType.__code__: types.GetSetDescriptorType, - types.FunctionType.__globals__: types.MemberDescriptorType, + MEMBER_DESCRIPTOR: types.MemberDescriptorType, METHOD_DESCRIPTOR_WRAPPER: types.MethodDescriptorType, METHOD_WRAPPER: types.MethodWrapperType, WRAPPER_DESCRIPTOR: types.WrapperDescriptorType, @@ -278,16 +279,11 @@ def ignore_byteswarning(): *defs.TOP_CLASSES, *USER_TOP_INSTANCES, *USER_EXCEPTIONS, - # from OTHER_TYPES - types.NoneType, - types.EllipsisType, - types.NotImplementedType, - types.GenericAlias, - types.UnionType, - types.SimpleNamespace, + *OTHER_TYPES, # from BUILTIN_WRAPPERS METHOD, BUILTIN_METHOD, + MEMBER_DESCRIPTOR, METHOD_DESCRIPTOR_WRAPPER, METHOD_WRAPPER, WRAPPER_DESCRIPTOR, diff --git a/Lib/test/test_exception_group.py b/Lib/test/test_exception_group.py index 35ffc9a0a4cf30a..9473aa9fb1d9e93 100644 --- a/Lib/test/test_exception_group.py +++ b/Lib/test/test_exception_group.py @@ -267,7 +267,7 @@ def __repr__(self): seq = MySeq(None) with self.assertRaisesRegex( TypeError, - r".*MySeq\.__repr__\(\) must return a str, not NoneType" + r".*MySeq\.__repr__\(\) must return a str, not types.NoneType" ): ExceptionGroup("test", seq) diff --git a/Lib/test/test_frame.py b/Lib/test/test_frame.py index 18ade18d1a1708c..4a90ce7b322fcfd 100644 --- a/Lib/test/test_frame.py +++ b/Lib/test/test_frame.py @@ -579,7 +579,7 @@ class ObjectSubclass: def test_constructor(self): FrameLocalsProxy = type([sys._getframe().f_locals for x in range(1)][0]) - self.assertEqual(FrameLocalsProxy.__name__, 'FrameLocalsProxy') + self.assertEqual(FrameLocalsProxy.__name__, 'FrameLocalsProxyType') def make_frame(): x = 1 diff --git a/Lib/test/test_gdb/test_backtrace.py b/Lib/test/test_gdb/test_backtrace.py index 714853c7b4732d9..efb60b621334032 100644 --- a/Lib/test/test_gdb/test_backtrace.py +++ b/Lib/test/test_gdb/test_backtrace.py @@ -20,7 +20,7 @@ def test_bt(self): self.assertMultilineMatches(bt, r'''^.* Traceback \(most recent call first\): - + File ".*gdb_sample.py", line 10, in baz id\(42\) File ".*gdb_sample.py", line 7, in bar diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py index c905c0da0a12327..877084ccd581d12 100644 --- a/Lib/test/test_import/__init__.py +++ b/Lib/test/test_import/__init__.py @@ -1262,7 +1262,7 @@ class Spec: self.assertIs(_imp.create_builtin(spec), sys) spec.name = None - with self.assertRaisesRegex(TypeError, 'name must be string, not NoneType'): + with self.assertRaisesRegex(TypeError, 'name must be string, not types.NoneType'): _imp.create_builtin(spec) # gh-142029 diff --git a/Lib/test/test_json/test_default.py b/Lib/test/test_json/test_default.py index 811880a15c80208..7868a2540afb15b 100644 --- a/Lib/test/test_json/test_default.py +++ b/Lib/test/test_json/test_default.py @@ -21,9 +21,9 @@ def default(obj): with self.assertRaises(ValueError) as cm: self.dumps(type, default=default) self.assertEqual(cm.exception.__notes__, - ['when serializing ellipsis object', + ['when serializing types.EllipsisType object', 'when serializing list item 0', - 'when serializing module object', + 'when serializing types.ModuleType object', 'when serializing type object']) def test_ordereddict(self): diff --git a/Lib/test/test_lazy_import/__init__.py b/Lib/test/test_lazy_import/__init__.py index 321733a4fdf1705..61d9786433dea79 100644 --- a/Lib/test/test_lazy_import/__init__.py +++ b/Lib/test/test_lazy_import/__init__.py @@ -287,7 +287,7 @@ def test_lazy_value_resolve(self): def test_lazy_import_type_exposed(self): """LazyImportType should be exposed in types module.""" self.assertHasAttr(types, 'LazyImportType') - self.assertEqual(types.LazyImportType.__name__, 'lazy_import') + self.assertEqual(types.LazyImportType.__name__, 'LazyImportType') def test_lazy_import_type_cant_construct(self): """LazyImportType should not be directly constructible.""" @@ -301,7 +301,7 @@ def test_lazy_import_type_attributes_accessible(self): print(globals()["json"].resolve) """) proc = assert_python_ok("-c", code) - self.assertIn(b" import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace() (Pdb) import sys (Pdb) sys.exc_info() - (, ValueError('Correct'), ) + (, ValueError('Correct'), ) (Pdb) continue """ diff --git a/Lib/test/test_pydoc/test_pydoc.py b/Lib/test/test_pydoc/test_pydoc.py index 5cd26923f75c311..a50aa6bb62e31ae 100644 --- a/Lib/test/test_pydoc/test_pydoc.py +++ b/Lib/test/test_pydoc/test_pydoc.py @@ -770,7 +770,7 @@ def run_pydoc_for_request(request, expected_text_part): # test for special True, False, None keywords run_pydoc_for_request('True', 'class bool(int)') run_pydoc_for_request('False', 'class bool(int)') - run_pydoc_for_request('None', 'class NoneType(object)') + run_pydoc_for_request('None', 'class NoneType(builtins.object)') # test for keyword "assert" run_pydoc_for_request('assert', 'The "assert" statement') # test for topic "TYPES" diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index f51f6a0bd4b6bfa..d7c27493c2f6bbf 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -719,8 +719,8 @@ def test_frame_locals_proxy_type(self): self.assertIsNone(types.FrameLocalsProxyType.__doc__) else: self.assertIsInstance(types.FrameLocalsProxyType.__doc__, str) - self.assertEqual(types.FrameLocalsProxyType.__module__, 'builtins') - self.assertEqual(types.FrameLocalsProxyType.__name__, 'FrameLocalsProxy') + self.assertEqual(types.FrameLocalsProxyType.__module__, 'types') + self.assertEqual(types.FrameLocalsProxyType.__name__, 'FrameLocalsProxyType') frame = inspect.currentframe() self.assertIsNotNone(frame) @@ -1401,7 +1401,8 @@ def test_richcompare(self): self.assertFalse(mp1 == mp2) self.assertTrue(mp1 != mp2) - msg = "not supported between instances of 'mappingproxy' and 'mappingproxy'" + msg = (r"not supported between instances of " + r"'types\.MappingProxyType' and 'types\.MappingProxyType'") with self.assertRaisesRegex(TypeError, msg): mp1 > mp2 diff --git a/Lib/test/test_unittest/test_async_case.py b/Lib/test/test_unittest/test_async_case.py index 91d45283eb3b1bb..496a0ca8d56242e 100644 --- a/Lib/test/test_unittest/test_async_case.py +++ b/Lib/test/test_unittest/test_async_case.py @@ -321,7 +321,7 @@ async def test3(self): self.assertIn('It is deprecated to return a value that is not None', str(w.warning)) self.assertIn('test2', str(w.warning)) self.assertEqual(w.filename, __file__) - self.assertIn("returned 'async_generator'", str(w.warning)) + self.assertIn("returned 'AsyncGeneratorType'", str(w.warning)) with self.assertWarns(DeprecationWarning) as w: Test('test3').run() diff --git a/Lib/test/test_unittest/test_case.py b/Lib/test/test_unittest/test_case.py index 83b42918e1eff6d..996508a87972fab 100644 --- a/Lib/test/test_unittest/test_case.py +++ b/Lib/test/test_unittest/test_case.py @@ -337,7 +337,7 @@ def test3(self): self.assertIn('It is deprecated to return a value that is not None', str(w.warning)) self.assertIn('test2', str(w.warning)) self.assertEqual(w.filename, __file__) - self.assertIn("returned 'generator'", str(w.warning)) + self.assertIn("returned 'GeneratorType'", str(w.warning)) with self.assertWarns(DeprecationWarning) as w: Foo('test3').run() @@ -359,7 +359,7 @@ async def test1(self): self.assertIn('It is deprecated to return a value that is not None', str(w.warning)) self.assertIn('test1', str(w.warning)) self.assertEqual(w.filename, __file__) - self.assertIn("returned 'coroutine'", str(w.warning)) + self.assertIn("returned 'CoroutineType'", str(w.warning)) self.assertIn( 'Maybe you forgot to use IsolatedAsyncioTestCase as the base class?', str(w.warning), diff --git a/Lib/test/test_unpack_ex.py b/Lib/test/test_unpack_ex.py index 33c96b84964b591..47726dc2468d8b6 100644 --- a/Lib/test/test_unpack_ex.py +++ b/Lib/test/test_unpack_ex.py @@ -364,7 +364,7 @@ >>> def f(arg): ... print(type(arg), list(arg), list(arg)) >>> f(*x for x in [[1,2,3]]) - [1, 2, 3] [] + [1, 2, 3] [] Iterable argument unpacking diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py index bf1bcf8e6ed5d9a..7be113a08c1f956 100644 --- a/Lib/test/test_warnings/__init__.py +++ b/Lib/test/test_warnings/__init__.py @@ -2176,7 +2176,7 @@ class Foo: ... with self.assertRaisesRegex( TypeError, - "Expected an object of type str for 'message', not 'function'" + "Expected an object of type str for 'message', not 'FunctionType'" ): @deprecated def foo(): ... diff --git a/Objects/capsule.c b/Objects/capsule.c index 16ae65905ef5ac0..f51c1436ac4a55c 100644 --- a/Objects/capsule.c +++ b/Objects/capsule.c @@ -353,7 +353,7 @@ Python import mechanism to link to one another.\n\ PyTypeObject PyCapsule_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - .tp_name = "PyCapsule", + .tp_name = "types.CapsuleType", .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, .tp_basicsize = sizeof(PyCapsule), .tp_dealloc = capsule_dealloc, diff --git a/Objects/cellobject.c b/Objects/cellobject.c index 0f1202669adf500..f029fb698923e33 100644 --- a/Objects/cellobject.c +++ b/Objects/cellobject.c @@ -22,7 +22,7 @@ PyCell_New(PyObject *obj) } PyDoc_STRVAR(cell_new_doc, -"types.CellType([contents])\n" +"CellType([contents])\n" "--\n" "\n" "Create a new cell object.\n" diff --git a/Objects/clinic/descrobject.c.h b/Objects/clinic/descrobject.c.h index a0cfbeca84db124..d82edb0418cee86 100644 --- a/Objects/clinic/descrobject.c.h +++ b/Objects/clinic/descrobject.c.h @@ -9,7 +9,7 @@ preserve #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(mappingproxy_new__doc__, -"mappingproxy(mapping)\n" +"MappingProxyType(mapping)\n" "--\n" "\n" "Read-only proxy of a mapping."); @@ -44,7 +44,7 @@ mappingproxy_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) static const char * const _keywords[] = {"mapping", NULL}; static _PyArg_Parser _parser = { .keywords = _keywords, - .fname = "mappingproxy", + .fname = "MappingProxyType", .kwtuple = KWTUPLE, }; #undef KWTUPLE @@ -179,4 +179,4 @@ property_init(PyObject *self, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=2e8df497abc4f915 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=2f2695e34f607ef7 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/funcobject.c.h b/Objects/clinic/funcobject.c.h index fec743146466a45..13b1eb052607bec 100644 --- a/Objects/clinic/funcobject.c.h +++ b/Objects/clinic/funcobject.c.h @@ -9,180 +9,183 @@ preserve #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION() #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() -PyDoc_STRVAR(function___annotate____doc__, +PyDoc_STRVAR(types_FunctionType___annotate____doc__, "Get the code object for a function."); -#if defined(function___annotate___DOCSTR) -# undef function___annotate___DOCSTR +#if defined(types_FunctionType___annotate___DOCSTR) +# undef types_FunctionType___annotate___DOCSTR #endif -#define function___annotate___DOCSTR function___annotate____doc__ +#define types_FunctionType___annotate___DOCSTR types_FunctionType___annotate____doc__ -#if !defined(function___annotate___DOCSTR) -# define function___annotate___DOCSTR NULL +#if !defined(types_FunctionType___annotate___DOCSTR) +# define types_FunctionType___annotate___DOCSTR NULL #endif -#if defined(FUNCTION___ANNOTATE___GETSETDEF) -# undef FUNCTION___ANNOTATE___GETSETDEF -# define FUNCTION___ANNOTATE___GETSETDEF {"__annotate__", (getter)function___annotate___get, (setter)function___annotate___set, function___annotate___DOCSTR}, +#if defined(TYPES_FUNCTIONTYPE___ANNOTATE___GETSETDEF) +# undef TYPES_FUNCTIONTYPE___ANNOTATE___GETSETDEF +# define TYPES_FUNCTIONTYPE___ANNOTATE___GETSETDEF {"__annotate__", (getter)types_FunctionType___annotate___get, (setter)types_FunctionType___annotate___set, types_FunctionType___annotate___DOCSTR}, #else -# define FUNCTION___ANNOTATE___GETSETDEF {"__annotate__", (getter)function___annotate___get, NULL, function___annotate___DOCSTR}, +# define TYPES_FUNCTIONTYPE___ANNOTATE___GETSETDEF {"__annotate__", (getter)types_FunctionType___annotate___get, NULL, types_FunctionType___annotate___DOCSTR}, #endif static PyObject * -function___annotate___get_impl(PyFunctionObject *self); +types_FunctionType___annotate___get_impl(PyFunctionObject *self); static PyObject * -function___annotate___get(PyObject *self, void *Py_UNUSED(context)) +types_FunctionType___annotate___get(PyObject *self, void *Py_UNUSED(context)) { PyObject *return_value = NULL; Py_BEGIN_CRITICAL_SECTION(self); - return_value = function___annotate___get_impl((PyFunctionObject *)self); + return_value = types_FunctionType___annotate___get_impl((PyFunctionObject *)self); Py_END_CRITICAL_SECTION(); return return_value; } -#if !defined(function___annotate___DOCSTR) -# define function___annotate___DOCSTR NULL +#if !defined(types_FunctionType___annotate___DOCSTR) +# define types_FunctionType___annotate___DOCSTR NULL #endif -#if defined(FUNCTION___ANNOTATE___GETSETDEF) -# undef FUNCTION___ANNOTATE___GETSETDEF -# define FUNCTION___ANNOTATE___GETSETDEF {"__annotate__", (getter)function___annotate___get, (setter)function___annotate___set, function___annotate___DOCSTR}, +#if defined(TYPES_FUNCTIONTYPE___ANNOTATE___GETSETDEF) +# undef TYPES_FUNCTIONTYPE___ANNOTATE___GETSETDEF +# define TYPES_FUNCTIONTYPE___ANNOTATE___GETSETDEF {"__annotate__", (getter)types_FunctionType___annotate___get, (setter)types_FunctionType___annotate___set, types_FunctionType___annotate___DOCSTR}, #else -# define FUNCTION___ANNOTATE___GETSETDEF {"__annotate__", NULL, (setter)function___annotate___set, NULL}, +# define TYPES_FUNCTIONTYPE___ANNOTATE___GETSETDEF {"__annotate__", NULL, (setter)types_FunctionType___annotate___set, NULL}, #endif static int -function___annotate___set_impl(PyFunctionObject *self, PyObject *value); +types_FunctionType___annotate___set_impl(PyFunctionObject *self, + PyObject *value); static int -function___annotate___set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +types_FunctionType___annotate___set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) { int return_value; Py_BEGIN_CRITICAL_SECTION(self); - return_value = function___annotate___set_impl((PyFunctionObject *)self, value); + return_value = types_FunctionType___annotate___set_impl((PyFunctionObject *)self, value); Py_END_CRITICAL_SECTION(); return return_value; } -PyDoc_STRVAR(function___annotations____doc__, +PyDoc_STRVAR(types_FunctionType___annotations____doc__, "Dict of annotations in a function object."); -#if defined(function___annotations___DOCSTR) -# undef function___annotations___DOCSTR +#if defined(types_FunctionType___annotations___DOCSTR) +# undef types_FunctionType___annotations___DOCSTR #endif -#define function___annotations___DOCSTR function___annotations____doc__ +#define types_FunctionType___annotations___DOCSTR types_FunctionType___annotations____doc__ -#if !defined(function___annotations___DOCSTR) -# define function___annotations___DOCSTR NULL +#if !defined(types_FunctionType___annotations___DOCSTR) +# define types_FunctionType___annotations___DOCSTR NULL #endif -#if defined(FUNCTION___ANNOTATIONS___GETSETDEF) -# undef FUNCTION___ANNOTATIONS___GETSETDEF -# define FUNCTION___ANNOTATIONS___GETSETDEF {"__annotations__", (getter)function___annotations___get, (setter)function___annotations___set, function___annotations___DOCSTR}, +#if defined(TYPES_FUNCTIONTYPE___ANNOTATIONS___GETSETDEF) +# undef TYPES_FUNCTIONTYPE___ANNOTATIONS___GETSETDEF +# define TYPES_FUNCTIONTYPE___ANNOTATIONS___GETSETDEF {"__annotations__", (getter)types_FunctionType___annotations___get, (setter)types_FunctionType___annotations___set, types_FunctionType___annotations___DOCSTR}, #else -# define FUNCTION___ANNOTATIONS___GETSETDEF {"__annotations__", (getter)function___annotations___get, NULL, function___annotations___DOCSTR}, +# define TYPES_FUNCTIONTYPE___ANNOTATIONS___GETSETDEF {"__annotations__", (getter)types_FunctionType___annotations___get, NULL, types_FunctionType___annotations___DOCSTR}, #endif static PyObject * -function___annotations___get_impl(PyFunctionObject *self); +types_FunctionType___annotations___get_impl(PyFunctionObject *self); static PyObject * -function___annotations___get(PyObject *self, void *Py_UNUSED(context)) +types_FunctionType___annotations___get(PyObject *self, void *Py_UNUSED(context)) { PyObject *return_value = NULL; Py_BEGIN_CRITICAL_SECTION(self); - return_value = function___annotations___get_impl((PyFunctionObject *)self); + return_value = types_FunctionType___annotations___get_impl((PyFunctionObject *)self); Py_END_CRITICAL_SECTION(); return return_value; } -#if !defined(function___annotations___DOCSTR) -# define function___annotations___DOCSTR NULL +#if !defined(types_FunctionType___annotations___DOCSTR) +# define types_FunctionType___annotations___DOCSTR NULL #endif -#if defined(FUNCTION___ANNOTATIONS___GETSETDEF) -# undef FUNCTION___ANNOTATIONS___GETSETDEF -# define FUNCTION___ANNOTATIONS___GETSETDEF {"__annotations__", (getter)function___annotations___get, (setter)function___annotations___set, function___annotations___DOCSTR}, +#if defined(TYPES_FUNCTIONTYPE___ANNOTATIONS___GETSETDEF) +# undef TYPES_FUNCTIONTYPE___ANNOTATIONS___GETSETDEF +# define TYPES_FUNCTIONTYPE___ANNOTATIONS___GETSETDEF {"__annotations__", (getter)types_FunctionType___annotations___get, (setter)types_FunctionType___annotations___set, types_FunctionType___annotations___DOCSTR}, #else -# define FUNCTION___ANNOTATIONS___GETSETDEF {"__annotations__", NULL, (setter)function___annotations___set, NULL}, +# define TYPES_FUNCTIONTYPE___ANNOTATIONS___GETSETDEF {"__annotations__", NULL, (setter)types_FunctionType___annotations___set, NULL}, #endif static int -function___annotations___set_impl(PyFunctionObject *self, PyObject *value); +types_FunctionType___annotations___set_impl(PyFunctionObject *self, + PyObject *value); static int -function___annotations___set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +types_FunctionType___annotations___set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) { int return_value; Py_BEGIN_CRITICAL_SECTION(self); - return_value = function___annotations___set_impl((PyFunctionObject *)self, value); + return_value = types_FunctionType___annotations___set_impl((PyFunctionObject *)self, value); Py_END_CRITICAL_SECTION(); return return_value; } -PyDoc_STRVAR(function___type_params____doc__, +PyDoc_STRVAR(types_FunctionType___type_params____doc__, "Get the declared type parameters for a function."); -#if defined(function___type_params___DOCSTR) -# undef function___type_params___DOCSTR +#if defined(types_FunctionType___type_params___DOCSTR) +# undef types_FunctionType___type_params___DOCSTR #endif -#define function___type_params___DOCSTR function___type_params____doc__ +#define types_FunctionType___type_params___DOCSTR types_FunctionType___type_params____doc__ -#if !defined(function___type_params___DOCSTR) -# define function___type_params___DOCSTR NULL +#if !defined(types_FunctionType___type_params___DOCSTR) +# define types_FunctionType___type_params___DOCSTR NULL #endif -#if defined(FUNCTION___TYPE_PARAMS___GETSETDEF) -# undef FUNCTION___TYPE_PARAMS___GETSETDEF -# define FUNCTION___TYPE_PARAMS___GETSETDEF {"__type_params__", (getter)function___type_params___get, (setter)function___type_params___set, function___type_params___DOCSTR}, +#if defined(TYPES_FUNCTIONTYPE___TYPE_PARAMS___GETSETDEF) +# undef TYPES_FUNCTIONTYPE___TYPE_PARAMS___GETSETDEF +# define TYPES_FUNCTIONTYPE___TYPE_PARAMS___GETSETDEF {"__type_params__", (getter)types_FunctionType___type_params___get, (setter)types_FunctionType___type_params___set, types_FunctionType___type_params___DOCSTR}, #else -# define FUNCTION___TYPE_PARAMS___GETSETDEF {"__type_params__", (getter)function___type_params___get, NULL, function___type_params___DOCSTR}, +# define TYPES_FUNCTIONTYPE___TYPE_PARAMS___GETSETDEF {"__type_params__", (getter)types_FunctionType___type_params___get, NULL, types_FunctionType___type_params___DOCSTR}, #endif static PyObject * -function___type_params___get_impl(PyFunctionObject *self); +types_FunctionType___type_params___get_impl(PyFunctionObject *self); static PyObject * -function___type_params___get(PyObject *self, void *Py_UNUSED(context)) +types_FunctionType___type_params___get(PyObject *self, void *Py_UNUSED(context)) { PyObject *return_value = NULL; Py_BEGIN_CRITICAL_SECTION(self); - return_value = function___type_params___get_impl((PyFunctionObject *)self); + return_value = types_FunctionType___type_params___get_impl((PyFunctionObject *)self); Py_END_CRITICAL_SECTION(); return return_value; } -#if !defined(function___type_params___DOCSTR) -# define function___type_params___DOCSTR NULL +#if !defined(types_FunctionType___type_params___DOCSTR) +# define types_FunctionType___type_params___DOCSTR NULL #endif -#if defined(FUNCTION___TYPE_PARAMS___GETSETDEF) -# undef FUNCTION___TYPE_PARAMS___GETSETDEF -# define FUNCTION___TYPE_PARAMS___GETSETDEF {"__type_params__", (getter)function___type_params___get, (setter)function___type_params___set, function___type_params___DOCSTR}, +#if defined(TYPES_FUNCTIONTYPE___TYPE_PARAMS___GETSETDEF) +# undef TYPES_FUNCTIONTYPE___TYPE_PARAMS___GETSETDEF +# define TYPES_FUNCTIONTYPE___TYPE_PARAMS___GETSETDEF {"__type_params__", (getter)types_FunctionType___type_params___get, (setter)types_FunctionType___type_params___set, types_FunctionType___type_params___DOCSTR}, #else -# define FUNCTION___TYPE_PARAMS___GETSETDEF {"__type_params__", NULL, (setter)function___type_params___set, NULL}, +# define TYPES_FUNCTIONTYPE___TYPE_PARAMS___GETSETDEF {"__type_params__", NULL, (setter)types_FunctionType___type_params___set, NULL}, #endif static int -function___type_params___set_impl(PyFunctionObject *self, PyObject *value); +types_FunctionType___type_params___set_impl(PyFunctionObject *self, + PyObject *value); static int -function___type_params___set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +types_FunctionType___type_params___set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) { int return_value; Py_BEGIN_CRITICAL_SECTION(self); - return_value = function___type_params___set_impl((PyFunctionObject *)self, value); + return_value = types_FunctionType___type_params___set_impl((PyFunctionObject *)self, value); Py_END_CRITICAL_SECTION(); return return_value; } PyDoc_STRVAR(func_new__doc__, -"function(code, globals, name=None, argdefs=None, closure=None,\n" -" kwdefaults=None)\n" +"FunctionType(code, globals, name=None, argdefs=None, closure=None,\n" +" kwdefaults=None)\n" "--\n" "\n" "Create a function object.\n" @@ -232,7 +235,7 @@ func_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) static const char * const _keywords[] = {"code", "globals", "name", "argdefs", "closure", "kwdefaults", NULL}; static _PyArg_Parser _parser = { .keywords = _keywords, - .fname = "function", + .fname = "FunctionType", .kwtuple = KWTUPLE, }; #undef KWTUPLE @@ -253,12 +256,12 @@ func_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) goto exit; } if (!PyObject_TypeCheck(fastargs[0], &PyCode_Type)) { - _PyArg_BadArgument("function", "argument 'code'", (&PyCode_Type)->tp_name, fastargs[0]); + _PyArg_BadArgument("FunctionType", "argument 'code'", (&PyCode_Type)->tp_name, fastargs[0]); goto exit; } code = (PyCodeObject *)fastargs[0]; if (!PyDict_Check(fastargs[1])) { - _PyArg_BadArgument("function", "argument 'globals'", "dict", fastargs[1]); + _PyArg_BadArgument("FunctionType", "argument 'globals'", "dict", fastargs[1]); goto exit; } globals = fastargs[1]; @@ -290,4 +293,4 @@ func_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=12cb900088d41bdb input=a9049054013a1b77]*/ +/*[clinic end generated code: output=ac23046b5846bea4 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/moduleobject.c.h b/Objects/clinic/moduleobject.c.h index 455b883c52e31ab..835afa24eb362d7 100644 --- a/Objects/clinic/moduleobject.c.h +++ b/Objects/clinic/moduleobject.c.h @@ -9,7 +9,7 @@ preserve #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(module___init____doc__, -"module(name, doc=None)\n" +"ModuleType(name, doc=None)\n" "--\n" "\n" "Create a module object.\n" @@ -46,7 +46,7 @@ module___init__(PyObject *self, PyObject *args, PyObject *kwargs) static const char * const _keywords[] = {"name", "doc", NULL}; static _PyArg_Parser _parser = { .keywords = _keywords, - .fname = "module", + .fname = "ModuleType", .kwtuple = KWTUPLE, }; #undef KWTUPLE @@ -63,7 +63,7 @@ module___init__(PyObject *self, PyObject *args, PyObject *kwargs) goto exit; } if (!PyUnicode_Check(fastargs[0])) { - _PyArg_BadArgument("module", "argument 'name'", "str", fastargs[0]); + _PyArg_BadArgument("ModuleType", "argument 'name'", "str", fastargs[0]); goto exit; } name = fastargs[0]; @@ -77,4 +77,4 @@ module___init__(PyObject *self, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=523344ad09ab2ea1 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=eb7550e27914313d input=a9049054013a1b77]*/ diff --git a/Objects/descrobject.c b/Objects/descrobject.c index 9c267ee739d2369..f2aae0e6f338f3c 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -14,10 +14,11 @@ /*[clinic input] -class mappingproxy "mappingproxyobject *" "&PyDictProxy_Type" +module types +class types.MappingProxyType "mappingproxyobject *" "&PyDictProxy_Type" class property "propertyobject *" "&PyProperty_Type" [clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=556352653fd4c02e]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=4c16626dfaee9098]*/ static void descr_dealloc(PyObject *self) @@ -1255,7 +1256,7 @@ mappingproxy_check_mapping(PyObject *mapping) /*[clinic input] @classmethod -mappingproxy.__new__ as mappingproxy_new +types.MappingProxyType.__new__ as mappingproxy_new mapping: object @@ -1264,7 +1265,7 @@ Read-only proxy of a mapping. static PyObject * mappingproxy_new_impl(PyTypeObject *type, PyObject *mapping) -/*[clinic end generated code: output=65f27f02d5b68fa7 input=c156df096ef7590c]*/ +/*[clinic end generated code: output=65f27f02d5b68fa7 input=29b80727762902b3]*/ { mappingproxyobject *mappingproxy; diff --git a/Objects/frameobject.c b/Objects/frameobject.c index 7f73964c1fbf2b4..c1a88e9eecaae66 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -912,7 +912,7 @@ static PyMethodDef framelocalsproxy_methods[] = { }; PyDoc_STRVAR(framelocalsproxy_doc, -"FrameLocalsProxy($frame)\n" +"FrameLocalsProxyType($frame)\n" "--\n" "\n" "Create a write-through view of the locals dictionary for a frame.\n" @@ -922,7 +922,7 @@ PyDoc_STRVAR(framelocalsproxy_doc, PyTypeObject PyFrameLocalsProxy_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - .tp_name = "FrameLocalsProxy", + .tp_name = "types.FrameLocalsProxyType", .tp_basicsize = sizeof(PyFrameLocalsProxyObject), .tp_dealloc = framelocalsproxy_dealloc, .tp_repr = &framelocalsproxy_repr, diff --git a/Objects/funcobject.c b/Objects/funcobject.c index d248c007b12e04e..f7d42d1e0344504 100644 --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -624,9 +624,10 @@ static PyMemberDef func_memberlist[] = { }; /*[clinic input] -class function "PyFunctionObject *" "&PyFunction_Type" +module types +class types.FunctionType "PyFunctionObject *" "&PyFunction_Type" [clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=70af9c90aa2e71b0]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=c7191e310373bee1]*/ #include "clinic/funcobject.c.h" @@ -823,14 +824,14 @@ func_set_kwdefaults(PyObject *self, PyObject *value, void *Py_UNUSED(ignored)) /*[clinic input] @critical_section @getter -function.__annotate__ +types.FunctionType.__annotate__ Get the code object for a function. [clinic start generated code]*/ static PyObject * -function___annotate___get_impl(PyFunctionObject *self) -/*[clinic end generated code: output=5ec7219ff2bda9e6 input=7f3db11e3c3329f3]*/ +types_FunctionType___annotate___get_impl(PyFunctionObject *self) +/*[clinic end generated code: output=cc991cda9d527374 input=b12fd98f735b071f]*/ { if (self->func_annotate == NULL) { Py_RETURN_NONE; @@ -841,12 +842,13 @@ function___annotate___get_impl(PyFunctionObject *self) /*[clinic input] @critical_section @setter -function.__annotate__ +types.FunctionType.__annotate__ [clinic start generated code]*/ static int -function___annotate___set_impl(PyFunctionObject *self, PyObject *value) -/*[clinic end generated code: output=05b7dfc07ada66cd input=eb6225e358d97448]*/ +types_FunctionType___annotate___set_impl(PyFunctionObject *self, + PyObject *value) +/*[clinic end generated code: output=63c2c7ffdfa92852 input=79303a27161b8993]*/ { if (value == NULL) { PyErr_SetString(PyExc_TypeError, @@ -872,14 +874,14 @@ function___annotate___set_impl(PyFunctionObject *self, PyObject *value) /*[clinic input] @critical_section @getter -function.__annotations__ +types.FunctionType.__annotations__ Dict of annotations in a function object. [clinic start generated code]*/ static PyObject * -function___annotations___get_impl(PyFunctionObject *self) -/*[clinic end generated code: output=a4cf4c884c934cbb input=92643d7186c1ad0c]*/ +types_FunctionType___annotations___get_impl(PyFunctionObject *self) +/*[clinic end generated code: output=f54d706d12797627 input=b6c92ce89a027bbb]*/ { PyObject *d = NULL; if (self->func_annotations == NULL && @@ -895,12 +897,13 @@ function___annotations___get_impl(PyFunctionObject *self) /*[clinic input] @critical_section @setter -function.__annotations__ +types.FunctionType.__annotations__ [clinic start generated code]*/ static int -function___annotations___set_impl(PyFunctionObject *self, PyObject *value) -/*[clinic end generated code: output=a61795d4a95eede4 input=5302641f686f0463]*/ +types_FunctionType___annotations___set_impl(PyFunctionObject *self, + PyObject *value) +/*[clinic end generated code: output=8d9aee4699ea6a1f input=04ab3312a4c0709f]*/ { if (value == Py_None) value = NULL; @@ -920,14 +923,14 @@ function___annotations___set_impl(PyFunctionObject *self, PyObject *value) /*[clinic input] @critical_section @getter -function.__type_params__ +types.FunctionType.__type_params__ Get the declared type parameters for a function. [clinic start generated code]*/ static PyObject * -function___type_params___get_impl(PyFunctionObject *self) -/*[clinic end generated code: output=eb844d7ffca517a8 input=0864721484293724]*/ +types_FunctionType___type_params___get_impl(PyFunctionObject *self) +/*[clinic end generated code: output=d22a65506ec044c7 input=fd73aeba7df53e55]*/ { if (self->func_typeparams == NULL) { return PyTuple_New(0); @@ -940,12 +943,13 @@ function___type_params___get_impl(PyFunctionObject *self) /*[clinic input] @critical_section @setter -function.__type_params__ +types.FunctionType.__type_params__ [clinic start generated code]*/ static int -function___type_params___set_impl(PyFunctionObject *self, PyObject *value) -/*[clinic end generated code: output=038b4cda220e56fb input=3862fbd4db2b70e8]*/ +types_FunctionType___type_params___set_impl(PyFunctionObject *self, + PyObject *value) +/*[clinic end generated code: output=ef5e4d629aa710e1 input=3b696413aaed18a9]*/ { /* Not legal to del f.__type_params__ or to set it to anything * other than a tuple object. */ @@ -973,12 +977,12 @@ static PyGetSetDef func_getsetlist[] = { {"__code__", func_get_code, func_set_code}, {"__defaults__", func_get_defaults, func_set_defaults}, {"__kwdefaults__", func_get_kwdefaults, func_set_kwdefaults}, - FUNCTION___ANNOTATIONS___GETSETDEF - FUNCTION___ANNOTATE___GETSETDEF + TYPES_FUNCTIONTYPE___ANNOTATIONS___GETSETDEF + TYPES_FUNCTIONTYPE___ANNOTATE___GETSETDEF {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, {"__name__", func_get_name, func_set_name}, {"__qualname__", func_get_qualname, func_set_qualname}, - FUNCTION___TYPE_PARAMS___GETSETDEF + TYPES_FUNCTIONTYPE___TYPE_PARAMS___GETSETDEF {NULL} /* Sentinel */ }; @@ -994,7 +998,7 @@ static PyGetSetDef func_getsetlist[] = { /*[clinic input] @classmethod -function.__new__ as func_new +types.FunctionType.__new__ as func_new code: object(type="PyCodeObject *", subclass_of="&PyCode_Type") a code object globals: object(subclass_of="&PyDict_Type") @@ -1015,7 +1019,7 @@ static PyObject * func_new_impl(PyTypeObject *type, PyCodeObject *code, PyObject *globals, PyObject *name, PyObject *defaults, PyObject *closure, PyObject *kwdefaults) -/*[clinic end generated code: output=de72f4c22ac57144 input=20c9c9f04ad2d3f2]*/ +/*[clinic end generated code: output=de72f4c22ac57144 input=5aac05886273aa5d]*/ { PyFunctionObject *newfunc; Py_ssize_t nclosure; diff --git a/Objects/lazyimportobject.c b/Objects/lazyimportobject.c index fa1eb25047d9617..6f65e8483cb8fea 100644 --- a/Objects/lazyimportobject.c +++ b/Objects/lazyimportobject.c @@ -132,7 +132,7 @@ static PyMethodDef lazy_import_methods[] = { PyDoc_STRVAR(lazy_import_doc, -"lazy_import(builtins, name, fromlist=None, /)\n" +"types.LazyImportType(builtins, name, fromlist=None, /)\n" "--\n" "\n" "Represents a lazy import that will be resolved on first use.\n" @@ -143,7 +143,7 @@ PyDoc_STRVAR(lazy_import_doc, PyTypeObject PyLazyImport_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - .tp_name = "lazy_import", + .tp_name = "types.LazyImportType", .tp_basicsize = sizeof(PyLazyImportObject), .tp_dealloc = lazy_import_dealloc, .tp_repr = lazy_import_repr, diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index 0197dda00d281ca..6dab21e6c0413f6 100644 --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -1107,16 +1107,17 @@ _PyModule_ClearDict(PyObject *d) } /*[clinic input] -class module "PyModuleObject *" "&PyModule_Type" +module types +class types.ModuleType "PyModuleObject *" "&PyModule_Type" [clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=3e35d4f708ecb6af]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=f7714cd5eea95264]*/ #include "clinic/moduleobject.c.h" /* Methods */ /*[clinic input] -module.__init__ +types.ModuleType.__init__ as module___init__ name: unicode doc: object = None @@ -1127,7 +1128,7 @@ The name must be a string; the optional doc argument can have any type. static int module___init___impl(PyModuleObject *self, PyObject *name, PyObject *doc) -/*[clinic end generated code: output=e7e721c26ce7aad7 input=57f9e177401e5e1e]*/ +/*[clinic end generated code: output=e7e721c26ce7aad7 input=d0de878d04b93f9d]*/ { return module_init_dict(self, self->md_dict, name, doc); } diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c index f96d58649984cc8..17ef53884702a8c 100644 --- a/Objects/sliceobject.c +++ b/Objects/sliceobject.c @@ -63,7 +63,7 @@ static PyMethodDef ellipsis_methods[] = { }; PyDoc_STRVAR(ellipsis_doc, -"ellipsis()\n" +"EllipsisType()\n" "--\n\n" "The type of the Ellipsis singleton."); diff --git a/Python/clinic/traceback.c.h b/Python/clinic/traceback.c.h index deae2efa3eb28d2..4a9afa742e40841 100644 --- a/Python/clinic/traceback.c.h +++ b/Python/clinic/traceback.c.h @@ -10,7 +10,7 @@ preserve #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() PyDoc_STRVAR(tb_new__doc__, -"traceback(tb_next, tb_frame, tb_lasti, tb_lineno)\n" +"TracebackType(tb_next, tb_frame, tb_lasti, tb_lineno)\n" "--\n" "\n" "Create a new traceback object."); @@ -46,7 +46,7 @@ tb_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) static const char * const _keywords[] = {"tb_next", "tb_frame", "tb_lasti", "tb_lineno", NULL}; static _PyArg_Parser _parser = { .keywords = _keywords, - .fname = "traceback", + .fname = "TracebackType", .kwtuple = KWTUPLE, }; #undef KWTUPLE @@ -65,7 +65,7 @@ tb_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) } tb_next = fastargs[0]; if (!PyObject_TypeCheck(fastargs[1], &PyFrame_Type)) { - _PyArg_BadArgument("traceback", "argument 'tb_frame'", (&PyFrame_Type)->tp_name, fastargs[1]); + _PyArg_BadArgument("TracebackType", "argument 'tb_frame'", (&PyFrame_Type)->tp_name, fastargs[1]); goto exit; } tb_frame = (PyFrameObject *)fastargs[1]; @@ -83,53 +83,54 @@ tb_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) return return_value; } -#if !defined(traceback_tb_next_DOCSTR) -# define traceback_tb_next_DOCSTR NULL +#if !defined(types_TracebackType_tb_next_DOCSTR) +# define types_TracebackType_tb_next_DOCSTR NULL #endif -#if defined(TRACEBACK_TB_NEXT_GETSETDEF) -# undef TRACEBACK_TB_NEXT_GETSETDEF -# define TRACEBACK_TB_NEXT_GETSETDEF {"tb_next", (getter)traceback_tb_next_get, (setter)traceback_tb_next_set, traceback_tb_next_DOCSTR}, +#if defined(TYPES_TRACEBACKTYPE_TB_NEXT_GETSETDEF) +# undef TYPES_TRACEBACKTYPE_TB_NEXT_GETSETDEF +# define TYPES_TRACEBACKTYPE_TB_NEXT_GETSETDEF {"tb_next", (getter)types_TracebackType_tb_next_get, (setter)types_TracebackType_tb_next_set, types_TracebackType_tb_next_DOCSTR}, #else -# define TRACEBACK_TB_NEXT_GETSETDEF {"tb_next", (getter)traceback_tb_next_get, NULL, traceback_tb_next_DOCSTR}, +# define TYPES_TRACEBACKTYPE_TB_NEXT_GETSETDEF {"tb_next", (getter)types_TracebackType_tb_next_get, NULL, types_TracebackType_tb_next_DOCSTR}, #endif static PyObject * -traceback_tb_next_get_impl(PyTracebackObject *self); +types_TracebackType_tb_next_get_impl(PyTracebackObject *self); static PyObject * -traceback_tb_next_get(PyObject *self, void *Py_UNUSED(context)) +types_TracebackType_tb_next_get(PyObject *self, void *Py_UNUSED(context)) { PyObject *return_value = NULL; Py_BEGIN_CRITICAL_SECTION(self); - return_value = traceback_tb_next_get_impl((PyTracebackObject *)self); + return_value = types_TracebackType_tb_next_get_impl((PyTracebackObject *)self); Py_END_CRITICAL_SECTION(); return return_value; } -#if !defined(traceback_tb_next_DOCSTR) -# define traceback_tb_next_DOCSTR NULL +#if !defined(types_TracebackType_tb_next_DOCSTR) +# define types_TracebackType_tb_next_DOCSTR NULL #endif -#if defined(TRACEBACK_TB_NEXT_GETSETDEF) -# undef TRACEBACK_TB_NEXT_GETSETDEF -# define TRACEBACK_TB_NEXT_GETSETDEF {"tb_next", (getter)traceback_tb_next_get, (setter)traceback_tb_next_set, traceback_tb_next_DOCSTR}, +#if defined(TYPES_TRACEBACKTYPE_TB_NEXT_GETSETDEF) +# undef TYPES_TRACEBACKTYPE_TB_NEXT_GETSETDEF +# define TYPES_TRACEBACKTYPE_TB_NEXT_GETSETDEF {"tb_next", (getter)types_TracebackType_tb_next_get, (setter)types_TracebackType_tb_next_set, types_TracebackType_tb_next_DOCSTR}, #else -# define TRACEBACK_TB_NEXT_GETSETDEF {"tb_next", NULL, (setter)traceback_tb_next_set, NULL}, +# define TYPES_TRACEBACKTYPE_TB_NEXT_GETSETDEF {"tb_next", NULL, (setter)types_TracebackType_tb_next_set, NULL}, #endif static int -traceback_tb_next_set_impl(PyTracebackObject *self, PyObject *value); +types_TracebackType_tb_next_set_impl(PyTracebackObject *self, + PyObject *value); static int -traceback_tb_next_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) +types_TracebackType_tb_next_set(PyObject *self, PyObject *value, void *Py_UNUSED(context)) { int return_value; Py_BEGIN_CRITICAL_SECTION(self); - return_value = traceback_tb_next_set_impl((PyTracebackObject *)self, value); + return_value = types_TracebackType_tb_next_set_impl((PyTracebackObject *)self, value); Py_END_CRITICAL_SECTION(); return return_value; } -/*[clinic end generated code: output=5361141395da963e input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b62d6e604be349a8 input=a9049054013a1b77]*/ diff --git a/Python/traceback.c b/Python/traceback.c index 944a1a529502d89..a2055b3fb537427 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -61,9 +61,10 @@ extern char* _PyTokenizer_FindEncodingFilename(int, PyObject *); /*[clinic input] -class traceback "PyTracebackObject *" "&PyTraceback_Type" +module types +class types.TracebackType "PyTracebackObject *" "&PyTraceback_Type" [clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=cf96294b2bebc811]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=f8bd29fca0613108]*/ #define _PyTracebackObject_CAST(op) ((PyTracebackObject *)(op)) @@ -99,7 +100,7 @@ tb_create_raw(PyTracebackObject *next, PyFrameObject *frame, int lasti, /*[clinic input] @classmethod -traceback.__new__ as tb_new +types.TracebackType.__new__ as tb_new tb_next: object tb_frame: object(type='PyFrameObject *', subclass_of='&PyFrame_Type') @@ -112,7 +113,7 @@ Create a new traceback object. static PyObject * tb_new_impl(PyTypeObject *type, PyObject *tb_next, PyFrameObject *tb_frame, int tb_lasti, int tb_lineno) -/*[clinic end generated code: output=fa077debd72d861a input=b88143145454cb59]*/ +/*[clinic end generated code: output=fa077debd72d861a input=3afe6e1d938a4ad5]*/ { if (tb_next == Py_None) { tb_next = NULL; @@ -136,12 +137,12 @@ tb_dir(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(ignored)) /*[clinic input] @critical_section @getter -traceback.tb_next +types.TracebackType.tb_next [clinic start generated code]*/ static PyObject * -traceback_tb_next_get_impl(PyTracebackObject *self) -/*[clinic end generated code: output=963634df7d5fc837 input=8f6345f2b73cb965]*/ +types_TracebackType_tb_next_get_impl(PyTracebackObject *self) +/*[clinic end generated code: output=144e5e6ca59c9394 input=5381427dd747d546]*/ { PyObject* ret = (PyObject*)self->tb_next; if (!ret) { @@ -176,12 +177,13 @@ tb_lineno_get(PyObject *op, void *Py_UNUSED(_)) /*[clinic input] @critical_section @setter -traceback.tb_next +types.TracebackType.tb_next [clinic start generated code]*/ static int -traceback_tb_next_set_impl(PyTracebackObject *self, PyObject *value) -/*[clinic end generated code: output=d4868cbc48f2adac input=ce66367f85e3c443]*/ +types_TracebackType_tb_next_set_impl(PyTracebackObject *self, + PyObject *value) +/*[clinic end generated code: output=6d1d30b3c14d59da input=7ead5a9edf8cfd30]*/ { if (!value) { PyErr_Format(PyExc_TypeError, "can't delete tb_next attribute"); @@ -232,7 +234,7 @@ static PyMemberDef tb_memberlist[] = { }; static PyGetSetDef tb_getsetters[] = { - TRACEBACK_TB_NEXT_GETSETDEF + TYPES_TRACEBACKTYPE_TB_NEXT_GETSETDEF {"tb_lineno", tb_lineno_get, NULL, NULL, NULL}, {NULL} /* Sentinel */ }; From 4fdaf4d1cb1b99fd53a52960dc75d9833717571d Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 4 Jun 2026 19:29:47 +0300 Subject: [PATCH 7/7] Fix doctests. --- Doc/howto/argparse.rst | 2 +- Doc/howto/descriptor.rst | 4 ++-- Doc/library/doctest.rst | 4 ++-- Doc/library/re.rst | 2 +- Doc/library/typing.rst | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Doc/howto/argparse.rst b/Doc/howto/argparse.rst index 902c50de00803c5..b8b17bbab785b7b 100644 --- a/Doc/howto/argparse.rst +++ b/Doc/howto/argparse.rst @@ -555,7 +555,7 @@ And this is what it gives: Traceback (most recent call last): File "prog.py", line 11, in if args.verbosity >= 2: - TypeError: '>=' not supported between instances of 'NoneType' and 'int' + TypeError: '>=' not supported between instances of 'types.NoneType' and 'int' * First output went well, and fixes the bug we had before. diff --git a/Doc/howto/descriptor.rst b/Doc/howto/descriptor.rst index 60dff850a61e2b1..9b62254bafd5fab 100644 --- a/Doc/howto/descriptor.rst +++ b/Doc/howto/descriptor.rst @@ -1379,7 +1379,7 @@ and :attr:`~function.__doc__`. 'StaticMethod' >>> f = E_sim.f >>> type(f).__name__ - 'function' + 'FunctionType' >>> sm.__name__ 'f' >>> f.__name__ @@ -1523,7 +1523,7 @@ Using the non-data descriptor protocol, a pure Python version of # Verify that __wrapped__ was added and works correctly >>> f = vars(T)['cm'].__wrapped__ >>> type(f).__name__ - 'function' + 'FunctionType' >>> f.__name__ 'cm' >>> f(T, 11, 22) diff --git a/Doc/library/doctest.rst b/Doc/library/doctest.rst index 3298697af8511b6..eb48fd2df7211f8 100644 --- a/Doc/library/doctest.rst +++ b/Doc/library/doctest.rst @@ -554,7 +554,7 @@ Some details you should read once, but won't need to remember: File "", line 1 1 + None ~~^~~~~~ - TypeError: unsupported operand type(s) for +: 'int' and 'NoneType' + TypeError: unsupported operand type(s) for +: 'int' and 'types.NoneType' Since the lines showing the position of the error come before the exception type and detail, they are not checked by doctest. For example, the following test @@ -564,7 +564,7 @@ Some details you should read once, but won't need to remember: File "", line 1 1 + None ^~~~~~~~ - TypeError: unsupported operand type(s) for +: 'int' and 'NoneType' + TypeError: unsupported operand type(s) for +: 'int' and 'types.NoneType' .. _option-flags-and-directives: diff --git a/Doc/library/re.rst b/Doc/library/re.rst index 4745c1b98a45543..2e60ee1b2c1fa57 100644 --- a/Doc/library/re.rst +++ b/Doc/library/re.rst @@ -1681,7 +1681,7 @@ To find out what card the pair consists of, one could use the Traceback (most recent call last): File "", line 1, in pair_re.prefixmatch("718ak").group(1) - AttributeError: 'NoneType' object has no attribute 'group' + AttributeError: 'types.NoneType' object has no attribute 'group' >>> pair_re.prefixmatch("354aa").group(1) 'a' diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index c909b8bad6d726c..0cb185720e85e86 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -1484,9 +1484,9 @@ These can be used as types in annotations. They all support subscription using >>> def func(x: Annotated[int, "metadata"]) -> None: pass ... >>> get_type_hints(func) - {'x': , 'return': } + {'x': , 'return': } >>> get_type_hints(func, include_extras=True) - {'x': typing.Annotated[int, 'metadata'], 'return': } + {'x': typing.Annotated[int, 'metadata'], 'return': } At runtime, the metadata associated with an ``Annotated`` type can be retrieved via the :attr:`!__metadata__` attribute: