summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2017-02-01 10:55:58 -0800
committerGuido van Rossum <guido@python.org>2017-02-01 10:55:58 -0800
commit0e4701169a3e3a022f03997399d04d28ca90c620 (patch)
tree025f13fa455d8d9c01d4ea5615f920eeb2085966 /Lib
parenta5d98c131bd07ee7adca2e1efb6557bf3e064838 (diff)
downloadcpython-0e4701169a3e3a022f03997399d04d28ca90c620.tar.gz
Issue #29377: Add three new wrappers to types.py (Manuel Krebber).
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_types.py18
-rw-r--r--Lib/types.py4
2 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py
index 382ca03e5a..4a9fcba526 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 d8d84709e1..1b7859e73a 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: