]> granicus.if.org Git - python/commitdiff
Issue #29377: Add three new wrappers to types.py (Manuel Krebber).
authorGuido van Rossum <guido@python.org>
Wed, 1 Feb 2017 18:55:58 +0000 (10:55 -0800)
committerGuido van Rossum <guido@python.org>
Wed, 1 Feb 2017 18:55:58 +0000 (10:55 -0800)
Doc/library/types.rst
Lib/test/test_types.py
Lib/types.py
Misc/NEWS

index 0c5619c713e86897dfbc4e4febf777c227adfa87..2602e3cf761f5c8f9e8907682aaa36a00ad6600f 100644 (file)
@@ -132,6 +132,29 @@ Standard names are defined for the following types:
    C".)
 
 
+.. data:: SlotWrapperType
+
+   The type of methods of some built-in data types and base classes such as
+   :meth:`object.__init__` or :meth:`object.__lt__`.
+
+   .. versionadded:: 3.7
+
+
+.. data:: MethodWrapperType
+
+   The type of *bound* methods of some built-in data types and base classes.
+   For example it is the type of :code:`object().__str__`.
+
+   .. versionadded:: 3.7
+
+
+.. data:: MethodDescriptorType
+
+   The type of methods of some built-in data types such as :meth:`str.join`.
+
+   .. versionadded:: 3.7
+
+
 .. class:: ModuleType(name, doc=None)
 
    The type of :term:`modules <module>`. Constructor takes the name of the
index 382ca03e5ad2b8deb843b504d5ad55b0e9c9ec6e..4a9fcba526af4d8a96d8cd6f157711377028a7a5 100644 (file)
@@ -576,6 +576,24 @@ class TypesTests(unittest.TestCase):
         self.assertGreater(object.__basicsize__, 0)
         self.assertGreater(tuple.__itemsize__, 0)
 
+    def test_slot_wrapper_types(self):
+        self.assertIsInstance(object.__init__, types.SlotWrapperType)
+        self.assertIsInstance(object.__str__, types.SlotWrapperType)
+        self.assertIsInstance(object.__lt__, types.SlotWrapperType)
+        self.assertIsInstance(int.__lt__, types.SlotWrapperType)
+
+    def test_method_wrapper_types(self):
+        self.assertIsInstance(object().__init__, types.MethodWrapperType)
+        self.assertIsInstance(object().__str__, types.MethodWrapperType)
+        self.assertIsInstance(object().__lt__, types.MethodWrapperType)
+        self.assertIsInstance((42).__lt__, types.MethodWrapperType)
+
+    def test_method_descriptor_types(self):
+        self.assertIsInstance(str.join, types.MethodDescriptorType)
+        self.assertIsInstance(list.append, types.MethodDescriptorType)
+        self.assertIsInstance(''.join, types.BuiltinMethodType)
+        self.assertIsInstance([].append, types.BuiltinMethodType)
+
 
 class MappingProxyTests(unittest.TestCase):
     mappingproxy = types.MappingProxyType
index d8d84709e1b97b7ec1cb88706e0ed347a9e47fd7..1b7859e73a19b9811483a670aecec7842c9934c0 100644 (file)
@@ -36,6 +36,10 @@ MethodType = type(_C()._m)
 BuiltinFunctionType = type(len)
 BuiltinMethodType = type([].append)     # Same as BuiltinFunctionType
 
+SlotWrapperType = type(object.__init__)
+MethodWrapperType = type(object().__str__)
+MethodDescriptorType = type(str.join)
+
 ModuleType = type(sys)
 
 try:
index 2db05148845d400a4e3d554bc6e2d8f6a36c90c4..21685d3a2381599f5aa674865743c225f201cc7c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -223,6 +223,10 @@ Extension Modules
 Library
 -------
 
+- Issue #29377: Add SlotWrapperType, MethodWrapperType, and
+  MethodDescriptorType built-in types to types module.
+  Original patch by Manuel Krebber.
+
 - Issue #29218: Unused install_misc command is now removed.  It has been
   documented as unused since 2000.  Patch by Eric N. Vander Weele.