diff options
author | Guido van Rossum <guido@python.org> | 2017-02-01 18:55:58 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2017-02-01 18:55:58 (GMT) |
commit | 934aba66ef09e94422bcac86dd221011242e141d (patch) | |
tree | 1532b2bb1743c8677025df35f328322abe23d456 | |
parent | 72268ae1c0f4bf4071c6e70bb6a332848a132d5d (diff) | |
download | cpython-934aba66ef09e94422bcac86dd221011242e141d.zip cpython-934aba66ef09e94422bcac86dd221011242e141d.tar.gz cpython-934aba66ef09e94422bcac86dd221011242e141d.tar.bz2 |
Issue #29377: Add three new wrappers to types.py (Manuel Krebber).
-rw-r--r-- | Doc/library/types.rst | 23 | ||||
-rw-r--r-- | Lib/test/test_types.py | 18 | ||||
-rw-r--r-- | Lib/types.py | 4 | ||||
-rw-r--r-- | Misc/NEWS | 4 |
4 files changed, 49 insertions, 0 deletions
diff --git a/Doc/library/types.rst b/Doc/library/types.rst index 0c5619c..2602e3c 100644 --- a/Doc/library/types.rst +++ b/Doc/library/types.rst @@ -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 diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index 382ca03..4a9fcba 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -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 diff --git a/Lib/types.py b/Lib/types.py index d8d8470..1b7859e 100644 --- a/Lib/types.py +++ b/Lib/types.py @@ -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: @@ -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. |