From 737216d2b73ae681e0cda305ec5a7233a9e03150 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sat, 5 Apr 2025 00:45:11 +0100 Subject: [PATCH 01/10] Expose more core types in ``_types`` --- Lib/types.py | 118 +++++++++++++++++++++-------------------- Modules/_typesmodule.c | 80 ++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+), 57 deletions(-) diff --git a/Lib/types.py b/Lib/types.py index 9aa0a3b087c1c7..2dd56d43af1dc4 100644 --- a/Lib/types.py +++ b/Lib/types.py @@ -2,67 +2,78 @@ Define names for built-in types that aren't directly accessible as a builtin. """ -import _types - # Iterators in Python aren't a matter of type but of protocol. A large # and changing number of builtin types implement *some* flavor of # iterator. Don't check the type! Use hasattr to check for both # "__iter__" and "__next__" attributes instead. -def _f(): pass -FunctionType = type(_f) -LambdaType = type(lambda: None) # Same as FunctionType -CodeType = type(_f.__code__) -MappingProxyType = type(type.__dict__) -SimpleNamespace = _types.SimpleNamespace - -def _cell_factory(): - a = 1 - def f(): - nonlocal a - return f.__closure__[0] -CellType = type(_cell_factory()) - -def _g(): - yield 1 -GeneratorType = type(_g()) - -async def _c(): pass -_c = _c() -CoroutineType = type(_c) -_c.close() # Prevent ResourceWarning - -async def _ag(): - yield -_ag = _ag() -AsyncGeneratorType = type(_ag) - -class _C: - def _m(self): pass -MethodType = type(_C()._m) - -BuiltinFunctionType = type(len) -BuiltinMethodType = type([].append) # Same as BuiltinFunctionType +try: + from _types import * +except ImportError: + import sys + + def _f(): pass + FunctionType = type(_f) + LambdaType = type(lambda: None) # Same as FunctionType + CodeType = type(_f.__code__) + MappingProxyType = type(type.__dict__) + SimpleNamespace = type(sys.implementation) + + def _cell_factory(): + a = 1 + def f(): + nonlocal a + return f.__closure__[0] + CellType = type(_cell_factory()) + + def _g(): + yield 1 + GeneratorType = type(_g()) + + async def _c(): pass + _c = _c() + CoroutineType = type(_c) + _c.close() # Prevent ResourceWarning + + async def _ag(): + yield + _ag = _ag() + AsyncGeneratorType = type(_ag) + + class _C: + def _m(self): pass + MethodType = type(_C()._m) + + BuiltinFunctionType = type(len) + BuiltinMethodType = type([].append) # Same as BuiltinFunctionType + + WrapperDescriptorType = type(object.__init__) + MethodWrapperType = type(object().__str__) + MethodDescriptorType = type(str.join) + ClassMethodDescriptorType = type(dict.__dict__['fromkeys']) + + ModuleType = type(sys) -WrapperDescriptorType = type(object.__init__) -MethodWrapperType = type(object().__str__) -MethodDescriptorType = type(str.join) -ClassMethodDescriptorType = type(dict.__dict__['fromkeys']) + try: + raise TypeError + except TypeError as exc: + TracebackType = type(exc.__traceback__) + FrameType = type(exc.__traceback__.tb_frame) -ModuleType = type(_types) + GetSetDescriptorType = type(FunctionType.__code__) + MemberDescriptorType = type(FunctionType.__globals__) -try: - raise TypeError -except TypeError as exc: - TracebackType = type(exc.__traceback__) - FrameType = type(exc.__traceback__.tb_frame) + GenericAlias = type(list[int]) + UnionType = type(int | str) -GetSetDescriptorType = type(FunctionType.__code__) -MemberDescriptorType = type(FunctionType.__globals__) + EllipsisType = type(Ellipsis) + NoneType = type(None) + NotImplementedType = type(NotImplemented) -CapsuleType = _types.CapsuleType + # CapsuleType cannot be accessed from pure Python, + # so there is no fallback definition. -del _types, _f, _g, _C, _c, _ag, _cell_factory # Not for export + del sys, _f, _g, _C, _c, _ag, _cell_factory # Not for export # Provide a PEP 3115 compliant mechanism for class creation @@ -326,11 +337,4 @@ def wrapped(*args, **kwargs): return wrapped -GenericAlias = type(list[int]) -UnionType = type(int | str) - -EllipsisType = type(Ellipsis) -NoneType = type(None) -NotImplementedType = type(NotImplemented) - __all__ = [n for n in globals() if not n.startswith('_')] # for pydoc diff --git a/Modules/_typesmodule.c b/Modules/_typesmodule.c index aabb35f47eefc3..46fac587867541 100644 --- a/Modules/_typesmodule.c +++ b/Modules/_typesmodule.c @@ -1,17 +1,97 @@ /* _types module */ #include "Python.h" +#include "pycore_descrobject.h" // _PyMethodWrapper_Type #include "pycore_namespace.h" // _PyNamespace_Type +#include "pycore_object.h" // _PyNone_Type, _PyNotImplemented_Type +#include "pycore_unionobject.h" // _PyUnion_Type static int _types_exec(PyObject *m) { + if (PyModule_AddObjectRef(m, "AsyncGeneratorType", (PyObject *)&PyAsyncGen_Type) < 0) { + return -1; + } + if (PyModule_AddObjectRef(m, "BuiltinFunctionType", (PyObject *)&PyCFunction_Type) < 0) { + return -1; + } + // Same as BuiltinMethodType + if (PyModule_AddObjectRef(m, "BuiltinMethodType", (PyObject *)&PyCFunction_Type) < 0) { + return -1; + } if (PyModule_AddObjectRef(m, "CapsuleType", (PyObject *)&PyCapsule_Type) < 0) { return -1; } + if (PyModule_AddObjectRef(m, "CellType", (PyObject *)&PyCell_Type) < 0) { + return -1; + } + if (PyModule_AddObjectRef(m, "ClassMethodDescriptorType", (PyObject *)&PyClassMethodDescr_Type) < 0) { + return -1; + } + if (PyModule_AddObjectRef(m, "CodeType", (PyObject *)&PyCode_Type) < 0) { + return -1; + } + if (PyModule_AddObjectRef(m, "CoroutineType", (PyObject *)&PyCoro_Type) < 0) { + return -1; + } + if (PyModule_AddObjectRef(m, "EllipsisType", (PyObject *)&PyEllipsis_Type) < 0) { + return -1; + } + if (PyModule_AddObjectRef(m, "FrameType", (PyObject *)&PyFrame_Type) < 0) { + return -1; + } + if (PyModule_AddObjectRef(m, "FunctionType", (PyObject *)&PyFunction_Type) < 0) { + return -1; + } + if (PyModule_AddObjectRef(m, "GeneratorType", (PyObject *)&PyGen_Type) < 0) { + return -1; + } + if (PyModule_AddObjectRef(m, "GenericAlias", (PyObject *)&Py_GenericAliasType) < 0) { + return -1; + } + if (PyModule_AddObjectRef(m, "GetSetDescriptorType", (PyObject *)&PyGetSetDescr_Type) < 0) { + return -1; + } + // Same as FunctionType + if (PyModule_AddObjectRef(m, "LambdaType", (PyObject *)&PyFunction_Type) < 0) { + return -1; + } + if (PyModule_AddObjectRef(m, "MappingProxyType", (PyObject *)&PyDictProxy_Type) < 0) { + return -1; + } + if (PyModule_AddObjectRef(m, "MemberDescriptorType", (PyObject *)&PyMemberDescr_Type) < 0) { + return -1; + } + if (PyModule_AddObjectRef(m, "MethodDescriptorType", (PyObject *)&PyMethodDescr_Type) < 0) { + return -1; + } + if (PyModule_AddObjectRef(m, "MethodType", (PyObject *)&PyMethod_Type) < 0) { + return -1; + } + if (PyModule_AddObjectRef(m, "MethodWrapperType", (PyObject *)&_PyMethodWrapper_Type) < 0) { + return -1; + } + if (PyModule_AddObjectRef(m, "ModuleType", (PyObject *)&PyModule_Type) < 0) { + return -1; + } + if (PyModule_AddObjectRef(m, "NoneType", (PyObject *)&_PyNone_Type) < 0) { + return -1; + } + if (PyModule_AddObjectRef(m, "NotImplementedType", (PyObject *)&_PyNotImplemented_Type) < 0) { + return -1; + } if (PyModule_AddObjectRef(m, "SimpleNamespace", (PyObject *)&_PyNamespace_Type) < 0) { return -1; } + if (PyModule_AddObjectRef(m, "TracebackType", (PyObject *)&PyTraceBack_Type) < 0) { + return -1; + } + if (PyModule_AddObjectRef(m, "UnionType", (PyObject *)&_PyUnion_Type) < 0) { + return -1; + } + if (PyModule_AddObjectRef(m, "WrapperDescriptorType", (PyObject *)&PyWrapperDescr_Type) < 0) { + return -1; + } return 0; } From 0c3c8be4ef062070cdf0557e0db76259667b2ae8 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sat, 5 Apr 2025 15:38:21 +0100 Subject: [PATCH 02/10] Use a macro --- Modules/_typesmodule.c | 118 +++++++++++++---------------------------- 1 file changed, 36 insertions(+), 82 deletions(-) diff --git a/Modules/_typesmodule.c b/Modules/_typesmodule.c index 46fac587867541..27fbe30cc4532d 100644 --- a/Modules/_typesmodule.c +++ b/Modules/_typesmodule.c @@ -9,89 +9,43 @@ static int _types_exec(PyObject *m) { - if (PyModule_AddObjectRef(m, "AsyncGeneratorType", (PyObject *)&PyAsyncGen_Type) < 0) { - return -1; - } - if (PyModule_AddObjectRef(m, "BuiltinFunctionType", (PyObject *)&PyCFunction_Type) < 0) { - return -1; - } - // Same as BuiltinMethodType - if (PyModule_AddObjectRef(m, "BuiltinMethodType", (PyObject *)&PyCFunction_Type) < 0) { - return -1; - } - if (PyModule_AddObjectRef(m, "CapsuleType", (PyObject *)&PyCapsule_Type) < 0) { - return -1; - } - if (PyModule_AddObjectRef(m, "CellType", (PyObject *)&PyCell_Type) < 0) { - return -1; - } - if (PyModule_AddObjectRef(m, "ClassMethodDescriptorType", (PyObject *)&PyClassMethodDescr_Type) < 0) { - return -1; - } - if (PyModule_AddObjectRef(m, "CodeType", (PyObject *)&PyCode_Type) < 0) { - return -1; - } - if (PyModule_AddObjectRef(m, "CoroutineType", (PyObject *)&PyCoro_Type) < 0) { - return -1; - } - if (PyModule_AddObjectRef(m, "EllipsisType", (PyObject *)&PyEllipsis_Type) < 0) { - return -1; - } - if (PyModule_AddObjectRef(m, "FrameType", (PyObject *)&PyFrame_Type) < 0) { - return -1; - } - if (PyModule_AddObjectRef(m, "FunctionType", (PyObject *)&PyFunction_Type) < 0) { - return -1; - } - if (PyModule_AddObjectRef(m, "GeneratorType", (PyObject *)&PyGen_Type) < 0) { - return -1; - } - if (PyModule_AddObjectRef(m, "GenericAlias", (PyObject *)&Py_GenericAliasType) < 0) { - return -1; - } - if (PyModule_AddObjectRef(m, "GetSetDescriptorType", (PyObject *)&PyGetSetDescr_Type) < 0) { - return -1; - } +#define EXPORT_STATIC_TYPE(NAME, TYPE) \ + do { \ + if (PyModule_AddObjectRef(m, (NAME), (PyObject *)&(TYPE)) < 0) { \ + return -1; \ + } \ + } while (0) + + EXPORT_STATIC_TYPE("AsyncGeneratorType", PyAsyncGen_Type); + EXPORT_STATIC_TYPE("BuiltinFunctionType", PyCFunction_Type); + // Same as BuiltinFunctionType + EXPORT_STATIC_TYPE("BuiltinMethodType", PyCFunction_Type); + EXPORT_STATIC_TYPE("CapsuleType", PyCapsule_Type); + EXPORT_STATIC_TYPE("CellType", PyCell_Type); + EXPORT_STATIC_TYPE("ClassMethodDescriptorType", PyClassMethodDescr_Type); + EXPORT_STATIC_TYPE("CodeType", PyCode_Type); + EXPORT_STATIC_TYPE("CoroutineType", PyCoro_Type); + EXPORT_STATIC_TYPE("EllipsisType", PyEllipsis_Type); + EXPORT_STATIC_TYPE("FrameType", PyFrame_Type); + EXPORT_STATIC_TYPE("FunctionType", PyFunction_Type); + EXPORT_STATIC_TYPE("GeneratorType", PyGen_Type); + EXPORT_STATIC_TYPE("GenericAlias", Py_GenericAliasType); + EXPORT_STATIC_TYPE("GetSetDescriptorType", PyGetSetDescr_Type); // Same as FunctionType - if (PyModule_AddObjectRef(m, "LambdaType", (PyObject *)&PyFunction_Type) < 0) { - return -1; - } - if (PyModule_AddObjectRef(m, "MappingProxyType", (PyObject *)&PyDictProxy_Type) < 0) { - return -1; - } - if (PyModule_AddObjectRef(m, "MemberDescriptorType", (PyObject *)&PyMemberDescr_Type) < 0) { - return -1; - } - if (PyModule_AddObjectRef(m, "MethodDescriptorType", (PyObject *)&PyMethodDescr_Type) < 0) { - return -1; - } - if (PyModule_AddObjectRef(m, "MethodType", (PyObject *)&PyMethod_Type) < 0) { - return -1; - } - if (PyModule_AddObjectRef(m, "MethodWrapperType", (PyObject *)&_PyMethodWrapper_Type) < 0) { - return -1; - } - if (PyModule_AddObjectRef(m, "ModuleType", (PyObject *)&PyModule_Type) < 0) { - return -1; - } - if (PyModule_AddObjectRef(m, "NoneType", (PyObject *)&_PyNone_Type) < 0) { - return -1; - } - if (PyModule_AddObjectRef(m, "NotImplementedType", (PyObject *)&_PyNotImplemented_Type) < 0) { - return -1; - } - if (PyModule_AddObjectRef(m, "SimpleNamespace", (PyObject *)&_PyNamespace_Type) < 0) { - return -1; - } - if (PyModule_AddObjectRef(m, "TracebackType", (PyObject *)&PyTraceBack_Type) < 0) { - return -1; - } - if (PyModule_AddObjectRef(m, "UnionType", (PyObject *)&_PyUnion_Type) < 0) { - return -1; - } - if (PyModule_AddObjectRef(m, "WrapperDescriptorType", (PyObject *)&PyWrapperDescr_Type) < 0) { - return -1; - } + EXPORT_STATIC_TYPE("LambdaType", PyFunction_Type); + EXPORT_STATIC_TYPE("MappingProxyType", PyDictProxy_Type); + EXPORT_STATIC_TYPE("MemberDescriptorType", PyMemberDescr_Type); + EXPORT_STATIC_TYPE("MethodDescriptorType", PyMethodDescr_Type); + EXPORT_STATIC_TYPE("MethodType", PyMethod_Type); + EXPORT_STATIC_TYPE("MethodWrapperType", _PyMethodWrapper_Type); + EXPORT_STATIC_TYPE("ModuleType", PyModule_Type); + EXPORT_STATIC_TYPE("NoneType", _PyNone_Type); + EXPORT_STATIC_TYPE("NotImplementedType", _PyNotImplemented_Type); + EXPORT_STATIC_TYPE("SimpleNamespace", _PyNamespace_Type); + EXPORT_STATIC_TYPE("TracebackType", PyTraceBack_Type); + EXPORT_STATIC_TYPE("UnionType", _PyUnion_Type); + EXPORT_STATIC_TYPE("WrapperDescriptorType", PyWrapperDescr_Type); +#undef ADD_STATIC_TYPE return 0; } From 51cd97b7a6c1b6fd5dbd736dcd69f8554bbdc256 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sat, 5 Apr 2025 15:57:40 +0100 Subject: [PATCH 03/10] Test that types are identical --- Lib/test/test_types.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index f014f7e9ee08c9..c29ea31c5ac75b 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -4,6 +4,8 @@ run_with_locale, cpython_only, no_rerun, MISSING_C_DOCSTRINGS, ) +from test.support.import_helper import import_fresh_module + import collections.abc from collections import namedtuple, UserDict import copy @@ -34,6 +36,17 @@ def clear_typing_caches(): class TypesTests(unittest.TestCase): + def test_names(self): + c_only_names = {'CapsuleType'} + ignored = {'new_class', 'resolve_bases', 'prepare_class', + 'get_original_bases', 'DynamicClassAttribute', 'coroutine'} + + c_types = import_fresh_module('types', fresh=['_types']) + py_types = import_fresh_module('types', blocked=['_types']) + for name in c_types.__all__: + if name not in c_only_names | ignored: + self.assertIs(getattr(c_types, name), getattr(py_types, name)) + def test_truth_values(self): if None: self.fail('None is true instead of false') if 0: self.fail('0 is true instead of false') From 84c2285941377482496963a79b0b25620f66c819 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Sat, 5 Apr 2025 16:35:03 +0100 Subject: [PATCH 04/10] fix typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Modules/_typesmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_typesmodule.c b/Modules/_typesmodule.c index 27fbe30cc4532d..d3a996baea33fa 100644 --- a/Modules/_typesmodule.c +++ b/Modules/_typesmodule.c @@ -45,7 +45,7 @@ _types_exec(PyObject *m) EXPORT_STATIC_TYPE("TracebackType", PyTraceBack_Type); EXPORT_STATIC_TYPE("UnionType", _PyUnion_Type); EXPORT_STATIC_TYPE("WrapperDescriptorType", PyWrapperDescr_Type); -#undef ADD_STATIC_TYPE +#undef EXPORT_STATIC_TYPE return 0; } From fd19ac662e2f6dd8a634ff3042337622a53ebcf9 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sat, 5 Apr 2025 16:50:59 +0100 Subject: [PATCH 05/10] Align comments --- Modules/_typesmodule.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/_typesmodule.c b/Modules/_typesmodule.c index d3a996baea33fa..7c49e06827f3a3 100644 --- a/Modules/_typesmodule.c +++ b/Modules/_typesmodule.c @@ -3,8 +3,8 @@ #include "Python.h" #include "pycore_descrobject.h" // _PyMethodWrapper_Type #include "pycore_namespace.h" // _PyNamespace_Type -#include "pycore_object.h" // _PyNone_Type, _PyNotImplemented_Type -#include "pycore_unionobject.h" // _PyUnion_Type +#include "pycore_object.h" // _PyNone_Type, _PyNotImplemented_Type +#include "pycore_unionobject.h" // _PyUnion_Type static int _types_exec(PyObject *m) From 74aac08440c1458666bb594fcfa42d1c2a98e935 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sat, 5 Apr 2025 16:58:42 +0100 Subject: [PATCH 06/10] Ensure EXPORT_STATIC_TYPE is used with static types --- Modules/_typesmodule.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Modules/_typesmodule.c b/Modules/_typesmodule.c index 7c49e06827f3a3..c7a0675540a905 100644 --- a/Modules/_typesmodule.c +++ b/Modules/_typesmodule.c @@ -11,6 +11,7 @@ _types_exec(PyObject *m) { #define EXPORT_STATIC_TYPE(NAME, TYPE) \ do { \ + assert(PyUnstable_IsImmortal((PyObject *)&(TYPE))); \ if (PyModule_AddObjectRef(m, (NAME), (PyObject *)&(TYPE)) < 0) { \ return -1; \ } \ From 0fbbf0ec14d0925d2281f05d47882223acf1742b Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sat, 5 Apr 2025 17:32:12 +0100 Subject: [PATCH 07/10] Update comments --- Modules/_typesmodule.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/_typesmodule.c b/Modules/_typesmodule.c index c7a0675540a905..a30a88196e7192 100644 --- a/Modules/_typesmodule.c +++ b/Modules/_typesmodule.c @@ -19,7 +19,7 @@ _types_exec(PyObject *m) EXPORT_STATIC_TYPE("AsyncGeneratorType", PyAsyncGen_Type); EXPORT_STATIC_TYPE("BuiltinFunctionType", PyCFunction_Type); - // Same as BuiltinFunctionType + // BuiltinMethodType is the same as BuiltinFunctionType EXPORT_STATIC_TYPE("BuiltinMethodType", PyCFunction_Type); EXPORT_STATIC_TYPE("CapsuleType", PyCapsule_Type); EXPORT_STATIC_TYPE("CellType", PyCell_Type); @@ -32,7 +32,7 @@ _types_exec(PyObject *m) EXPORT_STATIC_TYPE("GeneratorType", PyGen_Type); EXPORT_STATIC_TYPE("GenericAlias", Py_GenericAliasType); EXPORT_STATIC_TYPE("GetSetDescriptorType", PyGetSetDescr_Type); - // Same as FunctionType + // LambdaType is the same as FunctionType EXPORT_STATIC_TYPE("LambdaType", PyFunction_Type); EXPORT_STATIC_TYPE("MappingProxyType", PyDictProxy_Type); EXPORT_STATIC_TYPE("MemberDescriptorType", PyMemberDescr_Type); From 3dd8e04d376ba0a57486bf937d8772624c134229 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sat, 5 Apr 2025 18:20:59 +0100 Subject: [PATCH 08/10] Tweak `test_names()` --- Lib/test/test_types.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index c29ea31c5ac75b..0149f7a44288fc 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -21,6 +21,8 @@ import weakref import typing +c_types = import_fresh_module("types", fresh=["_types"]) +py_types = import_fresh_module("types", blocked=["_types"]) T = typing.TypeVar("T") @@ -41,12 +43,23 @@ def test_names(self): ignored = {'new_class', 'resolve_bases', 'prepare_class', 'get_original_bases', 'DynamicClassAttribute', 'coroutine'} - c_types = import_fresh_module('types', fresh=['_types']) - py_types = import_fresh_module('types', blocked=['_types']) for name in c_types.__all__: if name not in c_only_names | ignored: self.assertIs(getattr(c_types, name), getattr(py_types, name)) + all_names = ignored | { + 'AsyncGeneratorType', 'BuiltinFunctionType', 'BuiltinMethodType', + 'CapsuleType', 'CellType', 'ClassMethodDescriptorType', 'CodeType', + 'CoroutineType', 'EllipsisType', 'FrameType', 'FunctionType', + 'GeneratorType', 'GenericAlias', 'GetSetDescriptorType', + 'LambdaType', 'MappingProxyType', 'MemberDescriptorType', + 'MethodDescriptorType', 'MethodType', 'MethodWrapperType', + 'ModuleType', 'NoneType', 'NotImplementedType', 'SimpleNamespace', + 'TracebackType', 'UnionType', 'WrapperDescriptorType', + } + self.assertEqual(all_names, set(c_types.__all__)) + self.assertEqual(all_names - c_only_names, set(py_types.__all__)) + def test_truth_values(self): if None: self.fail('None is true instead of false') if 0: self.fail('0 is true instead of false') From de81f9719aa11b15c77f6b3b9c178a5495bedd1c Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sat, 5 Apr 2025 18:23:47 +0100 Subject: [PATCH 09/10] style --- Lib/test/test_types.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index 0149f7a44288fc..671f396d75be70 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -21,8 +21,8 @@ import weakref import typing -c_types = import_fresh_module("types", fresh=["_types"]) -py_types = import_fresh_module("types", blocked=["_types"]) +c_types = import_fresh_module('types', fresh=['_types']) +py_types = import_fresh_module('types', blocked=['_types']) T = typing.TypeVar("T") From 816d2bc2082e87bf1030d5201ac4d289096c2ecf Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Sat, 5 Apr 2025 18:45:56 +0100 Subject: [PATCH 10/10] whitespace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Lib/types.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/types.py b/Lib/types.py index 2dd56d43af1dc4..6efac3394345a5 100644 --- a/Lib/types.py +++ b/Lib/types.py @@ -14,7 +14,7 @@ def _f(): pass FunctionType = type(_f) - LambdaType = type(lambda: None) # Same as FunctionType + LambdaType = type(lambda: None) # Same as FunctionType CodeType = type(_f.__code__) MappingProxyType = type(type.__dict__) SimpleNamespace = type(sys.implementation) @@ -45,7 +45,7 @@ def _m(self): pass MethodType = type(_C()._m) BuiltinFunctionType = type(len) - BuiltinMethodType = type([].append) # Same as BuiltinFunctionType + BuiltinMethodType = type([].append) # Same as BuiltinFunctionType WrapperDescriptorType = type(object.__init__) MethodWrapperType = type(object().__str__) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy