diff --git a/Doc/howto/argparse.rst b/Doc/howto/argparse.rst index 902c50de00803c..b8b17bbab785b7 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 60dff850a61e2b..9b62254bafd5fa 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 3298697af8511b..eb48fd2df7211f 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/functools.rst b/Doc/library/functools.rst index 2b46978f058102..18761a7ce6e6d5 100644 --- a/Doc/library/functools.rst +++ b/Doc/library/functools.rst @@ -645,7 +645,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.shared_memory.rst b/Doc/library/multiprocessing.shared_memory.rst index e8f04a6ac7b95d..d7930f5c3e6ef0 100644 --- a/Doc/library/multiprocessing.shared_memory.rst +++ b/Doc/library/multiprocessing.shared_memory.rst @@ -365,7 +365,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/re.rst b/Doc/library/re.rst index 4745c1b98a4554..2e60ee1b2c1fa5 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 c909b8bad6d726..0cb185720e85e8 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: diff --git a/Doc/library/unittest.mock.rst b/Doc/library/unittest.mock.rst index 2ff1015af7a86e..a2daec601359a1 100644 --- a/Doc/library/unittest.mock.rst +++ b/Doc/library/unittest.mock.rst @@ -931,7 +931,7 @@ object:: ... >>> mock = MagicMock(async_func) >>> mock - + >>> mock() # doctest: +SKIP diff --git a/Lib/_pyrepl/fancycompleter.py b/Lib/_pyrepl/fancycompleter.py index ac4f0afdbc721c..d2afd7e1e00a77 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 9ba498ce8f575d..ee9a6ae47c4fb1 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', '') @@ -3300,6 +3300,35 @@ def test_builtin_types(self): s = self.dumps(t, proto) 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: + 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 = { 'BlockingIOError': (3, 3), diff --git a/Lib/test/test_call.py b/Lib/test/test_call.py index f42526aee19417..d6015520859a06 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_complex.py b/Lib/test/test_complex.py index bb307191dffcc1..6487693a8daec0 100644 --- a/Lib/test/test_complex.py +++ b/Lib/test/test_complex.py @@ -554,7 +554,7 @@ def check(z, x, y): "argument must be a string or a number, not dict", complex, {}) self.assertRaisesRegex(TypeError, - "argument must be a string or a number, not NoneType", + "argument must be a string or a number, not types.NoneType", complex, None) self.assertRaisesRegex(TypeError, "argument 'real' must be a real number, not dict", diff --git a/Lib/test/test_coroutines.py b/Lib/test/test_coroutines.py index 93e9e7a8393cb1..14ccd9762050f3 100644 --- a/Lib/test/test_coroutines.py +++ b/Lib/test/test_coroutines.py @@ -569,7 +569,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) @@ -601,7 +601,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(): @@ -963,7 +963,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_crossinterp.py b/Lib/test/test_crossinterp.py index f4bf5a66ad2155..941cad66c63488 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_csv.py b/Lib/test/test_csv.py index 7327c1bd5f5053..be7876a2e4c112 100644 --- a/Lib/test/test_csv.py +++ b/Lib/test/test_csv.py @@ -1215,7 +1215,7 @@ class mydialect(csv.Dialect): with self.assertRaises(csv.Error) as cm: mydialect() self.assertEqual(str(cm.exception), - '"delimiter" must be a unicode character, not NoneType') + '"delimiter" must be a unicode character, not types.NoneType') def test_escapechar(self): class mydialect(csv.Dialect): @@ -1281,7 +1281,7 @@ class mydialect(csv.Dialect): with self.assertRaises(csv.Error) as cm: mydialect() self.assertEqual(str(cm.exception), - '"lineterminator" must be a string, not NoneType') + '"lineterminator" must be a string, not types.NoneType') def test_invalid_chars(self): def create_invalid(field_name, value, **kwargs): diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 8a8e70214e27ae..f83bf8e7ae1364 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -5171,11 +5171,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_exception_group.py b/Lib/test/test_exception_group.py index 35ffc9a0a4cf30..9473aa9fb1d9e9 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_extcall.py b/Lib/test/test_extcall.py index 4da5601e80295f..539827616451e2 100644 --- a/Lib/test/test_extcall.py +++ b/Lib/test/test_extcall.py @@ -263,71 +263,71 @@ ... TypeError: h() got an unexpected keyword argument 'e' - >>> h(*h) + >>> h(*1) 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 - >>> 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: Value after * must be an iterable, not function + TypeError: Value after * must be an iterable, not int >>> nothing = None - >>> nothing(*h) + >>> nothing(*1) Traceback (most recent call last): ... - TypeError: Value after * must be an iterable, not function + TypeError: Value after * must be an iterable, not int - >>> h(**h) + >>> h(**1) Traceback (most recent call last): ... - TypeError: Value after ** must be a mapping, not function + TypeError: Value after ** must be a mapping, not int >>> h(**[]) Traceback (most recent call last): ... TypeError: Value after ** must be a mapping, not list - >>> h(a=1, **h) + >>> h(a=1, **2) Traceback (most recent call last): ... - TypeError: Value after ** must be a mapping, not function + TypeError: Value after ** must be a mapping, not int >>> h(a=1, **[]) Traceback (most recent call last): ... TypeError: Value after ** must be a mapping, not list - >>> h(**{'a': 1}, **h) + >>> h(**{'a': 1}, **2) Traceback (most recent call last): ... - TypeError: Value after ** must be a mapping, not function + TypeError: Value after ** must be a mapping, not int >>> h(**{'a': 1}, **[]) Traceback (most recent call last): ... TypeError: Value after ** must be a mapping, not list - >>> dir(**h) + >>> dir(**1) Traceback (most recent call last): ... - TypeError: Value after ** must be a mapping, not function + TypeError: Value after ** must be a mapping, not int - >>> nothing(**h) + >>> nothing(**1) Traceback (most recent call last): ... - TypeError: Value after ** must be a mapping, not function + TypeError: Value after ** must be a mapping, not int >>> class OnlyKeys: ... def keys(self): diff --git a/Lib/test/test_frame.py b/Lib/test/test_frame.py index 18ade18d1a1708..4a90ce7b322fcf 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_funcattrs.py b/Lib/test/test_funcattrs.py index fe14e7cb342c9e..876ca1fa9c93e9 100644 --- a/Lib/test/test_funcattrs.py +++ b/Lib/test/test_funcattrs.py @@ -141,7 +141,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/test_backtrace.py b/Lib/test/test_gdb/test_backtrace.py index 714853c7b4732d..efb60b62133403 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_gdb/test_misc.py b/Lib/test/test_gdb/test_misc.py index 1047f4867c1d03..e3f025db6dd54c 100644 --- a/Lib/test/test_gdb/test_misc.py +++ b/Lib/test/test_gdb/test_misc.py @@ -95,7 +95,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") @@ -124,7 +124,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\)\) $''') @@ -161,7 +161,7 @@ def test_printing_builtin(self): bt = self.get_stack_trace(script=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 6eb25960101a9e..b0b1af8eec3827 100644 --- a/Lib/test/test_generators.py +++ b/Lib/test/test_generators.py @@ -1361,10 +1361,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_state', 'gi_suspended', 'gi_yieldfrom', 'send', 'throw'] >>> from test.support import HAVE_DOCSTRINGS @@ -1381,11 +1381,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() @@ -1756,27 +1756,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 @@ -1800,7 +1800,7 @@ def b(): ... x = 1 ... return >>> type(f()) - + >>> def f(): ... if 0: @@ -1808,7 +1808,7 @@ def b(): ... yield 1 ... >>> type(f()) - + >>> def f(): ... if 0: @@ -1818,7 +1818,7 @@ def b(): ... def f(self): ... yield 2 >>> type(f()) - + >>> def f(): ... if 0: @@ -1826,7 +1826,7 @@ def b(): ... if 0: ... yield 2 >>> type(f()) - + This one caused a crash (see SF bug 567538): @@ -2477,7 +2477,7 @@ def printsolution(self, x): >>> def f(): list(i for i in [(yield 26)]) >>> type(f()) - + A yield expression with augmented assignment. @@ -2761,21 +2761,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 fe5f18fa3f88a0..94669bcc0d2333 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 ebcd98a0a37776..d510ff9263157b 100644 --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -1583,9 +1583,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_import/__init__.py b/Lib/test/test_import/__init__.py index c905c0da0a1232..877084ccd581d1 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 811880a15c8020..7868a2540afb15 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_json/test_fail.py b/Lib/test/test_json/test_fail.py index 79c44af2fbf0e1..30684a765fc526 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') as cm: + 'Object of type ModuleType is not JSON serializable') as cm: self.dumps(sys) self.assertNotHasAttr(cm.exception, '__notes__') diff --git a/Lib/test/test_lazy_import/__init__.py b/Lib/test/test_lazy_import/__init__.py index 321733a4fdf170..61d9786433dea7 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 5cd26923f75c31..a50aa6bb62e31a 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_richcmp.py b/Lib/test/test_richcmp.py index b967c7623c57b0..339d0e8d587a88 100644 --- a/Lib/test/test_richcmp.py +++ b/Lib/test/test_richcmp.py @@ -253,16 +253,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 94325f5a8003d9..b52be521d317a4 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -1018,7 +1018,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) @@ -1030,7 +1030,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 7dc3364561d8a1..4f0d7d221dc160 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -588,7 +588,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 2084b30d71ff6c..d7c27493c2f6bb 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 @@ -1661,7 +1662,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. @@ -1671,7 +1672,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_unittest/test_async_case.py b/Lib/test/test_unittest/test_async_case.py index 91d45283eb3b1b..496a0ca8d56242 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 83b42918e1eff6..996508a87972fa 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 33c96b84964b59..47726dc2468d8b 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 bf1bcf8e6ed5d9..7be113a08c1f95 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/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 00000000000000..e403d510308594 --- /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. diff --git a/Objects/capsule.c b/Objects/capsule.c index 16ae65905ef5ac..f51c1436ac4a55 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 ec2eeb1a855b63..f029fb698923e3 100644 --- a/Objects/cellobject.c +++ b/Objects/cellobject.c @@ -22,7 +22,7 @@ PyCell_New(PyObject *obj) } PyDoc_STRVAR(cell_new_doc, -"cell([contents])\n" +"CellType([contents])\n" "--\n" "\n" "Create a new cell object.\n" @@ -39,11 +39,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); @@ -171,7 +171,7 @@ static PyGetSetDef cell_getsetlist[] = { PyTypeObject PyCell_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "cell", + "types.CellType", sizeof(PyCellObject), 0, cell_dealloc, /* tp_dealloc */ diff --git a/Objects/classobject.c b/Objects/classobject.c index 238f1c1dad7d86..70155714aa5220 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -17,9 +17,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 * @@ -84,12 +84,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); @@ -116,7 +116,7 @@ method___reduce___impl(PyMethodObject *self) } static PyMethodDef method_methods[] = { - METHOD___REDUCE___METHODDEF + METHODTYPE___REDUCE___METHODDEF {NULL, NULL} }; @@ -183,7 +183,7 @@ method_getattro(PyObject *obj, PyObject *name) /*[clinic input] @classmethod -method.__new__ as method_new +MethodType.__new__ as method_new function: object instance: object / @@ -193,7 +193,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, @@ -312,7 +312,7 @@ method_descr_get(PyObject *meth, PyObject *obj, PyObject *cls) PyTypeObject PyMethod_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - .tp_name = "method", + .tp_name = "types.MethodType", .tp_basicsize = sizeof(PyMethodObject), .tp_dealloc = method_dealloc, .tp_vectorcall_offset = offsetof(PyMethodObject, vectorcall), diff --git a/Objects/clinic/classobject.c.h b/Objects/clinic/classobject.c.h index 5934f1c2a41669..491380394361bc 100644 --- a/Objects/clinic/classobject.c.h +++ b/Objects/clinic/classobject.c.h @@ -4,25 +4,25 @@ preserve #include "pycore_modsupport.h" // _PyArg_CheckPositional() -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__(PyObject *self, PyObject *Py_UNUSED(ignored)) +MethodType___reduce__(PyObject *self, PyObject *Py_UNUSED(ignored)) { - return method___reduce___impl((PyMethodObject *)self); + return MethodType___reduce___impl((PyMethodObject *)self); } PyDoc_STRVAR(method_new__doc__, -"method(function, instance, /)\n" +"MethodType(function, instance, /)\n" "--\n" "\n" "Create a bound instance method object."); @@ -39,10 +39,10 @@ method_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) PyObject *instance; if ((type == base_tp || type->tp_init == base_tp->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); @@ -82,4 +82,4 @@ instancemethod_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) exit: return return_value; } -/*[clinic end generated code: output=ab546abf90aac94e input=a9049054013a1b77]*/ +/*[clinic end generated code: output=e044d6a54d44b473 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/codeobject.c.h b/Objects/clinic/codeobject.c.h index 88333e9d3363eb..b9fba2da0d6a01 100644 --- a/Objects/clinic/codeobject.c.h +++ b/Objects/clinic/codeobject.c.h @@ -9,10 +9,10 @@ preserve #include "pycore_modsupport.h" // _PyArg_CheckPositional() 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) PyObject *cellvars = NULL; if ((type == base_tp || type->tp_init == base_tp->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,37 +82,37 @@ 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; } 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; } 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; } qualname = PyTuple_GET_ITEM(args, 12); @@ -121,12 +121,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); @@ -134,7 +134,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); @@ -142,7 +142,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); @@ -153,28 +153,29 @@ code_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) return return_value; } -PyDoc_STRVAR(code_replace__doc__, +PyDoc_STRVAR(types_CodeType_replace__doc__, "replace($self, /, **changes)\n" "--\n" "\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, PyObject *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, PyObject *co_linetable, - PyObject *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, PyObject *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, + PyObject *co_linetable, + PyObject *co_exceptiontable); static PyObject * -code_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +types_CodeType_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -402,13 +403,13 @@ code_replace(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject * } co_exceptiontable = args[17]; skip_optional_kwonly: - return_value = code_replace_impl((PyCodeObject *)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((PyCodeObject *)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" @@ -417,14 +418,14 @@ PyDoc_STRVAR(code__varname_from_oparg__doc__, "WARNING: this method is for internal use only and may change or go\n" "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(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +types_CodeType__varname_from_oparg(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) { PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) @@ -466,9 +467,9 @@ code__varname_from_oparg(PyObject *self, PyObject *const *args, Py_ssize_t nargs if (oparg == -1 && PyErr_Occurred()) { goto exit; } - return_value = code__varname_from_oparg_impl((PyCodeObject *)self, oparg); + return_value = types_CodeType__varname_from_oparg_impl((PyCodeObject *)self, oparg); exit: return return_value; } -/*[clinic end generated code: output=5c22e29e430401b4 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=c672676c8d003ee8 input=a9049054013a1b77]*/ diff --git a/Objects/clinic/descrobject.c.h b/Objects/clinic/descrobject.c.h index a0cfbeca84db12..d82edb0418cee8 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 fec743146466a4..13b1eb052607be 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 455b883c52e31a..835afa24eb362d 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/codeobject.c b/Objects/codeobject.c index 4ede8de6e8adc5..a49f4500c728b4 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -2249,13 +2249,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 @@ -2288,7 +2289,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; @@ -2296,7 +2297,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; @@ -2721,7 +2722,7 @@ code_branchesiterator(PyObject *self, PyObject *Py_UNUSED(args)) /*[clinic input] @permit_long_summary @text_signature "($self, /, **changes)" -code.replace +types.CodeType.replace * co_argcount: int(c_default="((PyCodeObject *)self)->co_argcount") = unchanged @@ -2747,16 +2748,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, PyObject *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, PyObject *co_linetable, - PyObject *co_exceptiontable) -/*[clinic end generated code: output=e75c48a15def18b9 input=e944fdac8b456114]*/ +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, PyObject *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, + PyObject *co_linetable, + PyObject *co_exceptiontable) +/*[clinic end generated code: output=5ce67c35dd196528 input=541fe425a6704797]*/ { #define CHECK_INT_ARG(ARG) \ if (ARG < 0) { \ @@ -2784,7 +2786,7 @@ code_replace_impl(PyCodeObject *self, int co_argcount, co_code = 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) { @@ -2834,7 +2836,7 @@ code_replace_impl(PyCodeObject *self, int co_argcount, } /*[clinic input] -code._varname_from_oparg +types.CodeType._varname_from_oparg oparg: int @@ -2845,8 +2847,8 @@ away. [clinic start generated code]*/ static PyObject * -code__varname_from_oparg_impl(PyCodeObject *self, int oparg) -/*[clinic end generated code: output=1fd1130413184206 input=6ba7d6df0d566463]*/ +types_CodeType__varname_from_oparg_impl(PyCodeObject *self, int oparg) +/*[clinic end generated code: output=92172b43d4b576c0 input=ab97b576a4b72411]*/ { PyObject *name = PyTuple_GetItem(self->co_localsplusnames, oparg); if (name == NULL) { @@ -2862,9 +2864,9 @@ static struct PyMethodDef code_methods[] = { {"co_lines", code_linesiterator, METH_NOARGS}, {"co_branches", code_branchesiterator, METH_NOARGS}, {"co_positions", code_positionsiterator, METH_NOARGS}, - CODE_REPLACE_METHODDEF - CODE__VARNAME_FROM_OPARG_METHODDEF - {"__replace__", _PyCFunction_CAST(code_replace), METH_FASTCALL|METH_KEYWORDS, + TYPES_CODETYPE_REPLACE_METHODDEF + TYPES_CODETYPE__VARNAME_FROM_OPARG_METHODDEF + {"__replace__", _PyCFunction_CAST(types_CodeType_replace), METH_FASTCALL|METH_KEYWORDS, PyDoc_STR("__replace__($self, /, **changes)\n--\n\nThe same as replace().")}, {NULL, NULL} /* sentinel */ }; @@ -2872,7 +2874,7 @@ static struct PyMethodDef code_methods[] = { PyTypeObject PyCode_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "code", + "types.CodeType", offsetof(PyCodeObject, co_code_adaptive), sizeof(_Py_CODEUNIT), code_dealloc, /* tp_dealloc */ diff --git a/Objects/descrobject.c b/Objects/descrobject.c index 30444b7d677424..f2aae0e6f338f3 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) @@ -716,7 +717,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, descr_dealloc, /* tp_dealloc */ @@ -756,7 +757,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, descr_dealloc, /* tp_dealloc */ @@ -793,7 +794,7 @@ PyTypeObject PyClassMethodDescr_Type = { PyTypeObject PyMemberDescr_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "member_descriptor", + "types.MemberDescriptorType", sizeof(PyMemberDescrObject), 0, descr_dealloc, /* tp_dealloc */ @@ -830,7 +831,7 @@ PyTypeObject PyMemberDescr_Type = { PyTypeObject PyGetSetDescr_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "getset_descriptor", + "types.GetSetDescriptorType", sizeof(PyGetSetDescrObject), 0, descr_dealloc, /* tp_dealloc */ @@ -867,7 +868,7 @@ PyTypeObject PyGetSetDescr_Type = { PyTypeObject PyWrapperDescr_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "wrapper_descriptor", + "types.WrapperDescriptorType", sizeof(PyWrapperDescrObject), 0, descr_dealloc, /* tp_dealloc */ @@ -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; @@ -1451,7 +1452,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 */ @@ -1999,7 +2000,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 f60cdb2dd1bf20..c1a88e9eecaae6 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, @@ -2068,7 +2068,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 0fffd36ad462da..f7d42d1e034450 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; @@ -1184,7 +1188,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, func_dealloc, /* tp_dealloc */ diff --git a/Objects/genobject.c b/Objects/genobject.c index 38d493343454fc..eba36c2bb5b4e7 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -1038,7 +1038,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.localsplus), /* tp_basicsize */ sizeof(PyObject *), /* tp_itemsize */ /* methods */ @@ -1389,7 +1389,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.localsplus),/* tp_basicsize */ sizeof(PyObject *), /* tp_itemsize */ /* methods */ @@ -1837,7 +1837,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.localsplus), /* tp_basicsize */ sizeof(PyObject *), /* tp_itemsize */ /* methods */ diff --git a/Objects/lazyimportobject.c b/Objects/lazyimportobject.c index fa1eb25047d961..6f65e8483cb8fe 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/methodobject.c b/Objects/methodobject.c index e6e469ca270ac9..d61d7aed04e39a 100644 --- a/Objects/methodobject.c +++ b/Objects/methodobject.c @@ -355,7 +355,7 @@ meth_hash(PyObject *self) PyTypeObject PyCFunction_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "builtin_function_or_method", + "types.BuiltinFunctionType", sizeof(PyCFunctionObject), 0, meth_dealloc, /* tp_dealloc */ diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index f447403ef31b43..6dab21e6c0413f 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); } @@ -1795,7 +1796,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 */ module_dealloc, /* tp_dealloc */ diff --git a/Objects/object.c b/Objects/object.c index e0e26bb50d3653..b0fa356abcd04a 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -2357,7 +2357,7 @@ PyDoc_STRVAR(none_doc, PyTypeObject _PyNone_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "NoneType", + "types.NoneType", 0, 0, none_dealloc, /*tp_dealloc*/ @@ -2457,7 +2457,7 @@ PyDoc_STRVAR(notimplemented_doc, 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 91d1753b822fc1..17ef53884702a8 100644 --- a/Objects/sliceobject.c +++ b/Objects/sliceobject.c @@ -63,13 +63,13 @@ static PyMethodDef ellipsis_methods[] = { }; PyDoc_STRVAR(ellipsis_doc, -"ellipsis()\n" +"EllipsisType()\n" "--\n\n" "The type of the Ellipsis singleton."); PyTypeObject PyEllipsis_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "ellipsis", /* tp_name */ + "types.EllipsisType", /* tp_name */ 0, /* tp_basicsize */ 0, /* tp_itemsize */ ellipsis_dealloc, /* tp_dealloc */ diff --git a/Python/clinic/traceback.c.h b/Python/clinic/traceback.c.h index deae2efa3eb28d..4a9afa742e4084 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 50a79d78d2e10e..a2055b3fb53742 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 */ }; @@ -267,7 +269,7 @@ tb_clear(PyObject *op) PyTypeObject PyTraceBack_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "traceback", + "types.TracebackType", sizeof(PyTracebackObject), 0, tb_dealloc, /*tp_dealloc*/ diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py index ba52ea2a30e0be..98401b030df6c1 100755 --- a/Tools/gdb/libpython.py +++ b/Tools/gdb/libpython.py @@ -349,12 +349,16 @@ 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, 'frozendict' : PyDictObjectPtr, '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]