diff -r 3d328ee18612 Doc/library/types.rst --- a/Doc/library/types.rst Mon Jan 30 13:56:20 2017 +0300 +++ b/Doc/library/types.rst Wed Feb 01 10:20:34 2017 +0100 @@ -131,7 +131,30 @@ methods of built-in classes. (Here, the term "built-in" means "written in 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 `. Constructor takes the name of the diff -r 3d328ee18612 Lib/test/test_types.py --- a/Lib/test/test_types.py Mon Jan 30 13:56:20 2017 +0300 +++ b/Lib/test/test_types.py Wed Feb 01 10:20:34 2017 +0100 @@ -576,6 +576,24 @@ 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 diff -r 3d328ee18612 Lib/types.py --- a/Lib/types.py Mon Jan 30 13:56:20 2017 +0300 +++ b/Lib/types.py Wed Feb 01 10:20:34 2017 +0100 @@ -36,6 +36,10 @@ 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: diff -r 3d328ee18612 Misc/NEWS --- a/Misc/NEWS Mon Jan 30 13:56:20 2017 +0300 +++ b/Misc/NEWS Wed Feb 01 10:20:34 2017 +0100 @@ -218,6 +218,10 @@ Library ------- +- Issue #29377: Add SlotWrapperType, MethodWrapperType, and + MethodDescriptorType built-in types to types module. + Original patch by Manuel Krebber. + - Issue #29338: The help of a builtin or extension class now includes the constructor signature if __text_signature__ is provided for the class.