From 4966c1cb947fa33dbb34b49840a1fc8c191330c6 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Fri, 19 Aug 2016 11:04:07 +0300 Subject: Issue #27157: Make only type() itself accept the one-argument form Patch by Eryk Sun and Emanuel Barry. --- Lib/test/test_types.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'Lib/test/test_types.py') diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index 5e741153f4..a202196bd2 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -1000,6 +1000,24 @@ class ClassCreationTests(unittest.TestCase): with self.assertRaises(TypeError): X = types.new_class("X", (int(), C)) + def test_one_argument_type(self): + expected_message = 'type.__new__() takes exactly 3 arguments (1 given)' + + # Only type itself can use the one-argument form (#27157) + self.assertIs(type(5), int) + + class M(type): + pass + with self.assertRaises(TypeError) as cm: + M(5) + self.assertEqual(str(cm.exception), expected_message) + + class N(type, metaclass=M): + pass + with self.assertRaises(TypeError) as cm: + N(5) + self.assertEqual(str(cm.exception), expected_message) + class SimpleNamespaceTests(unittest.TestCase): -- cgit v1.2.1 From 823616bdc22856b5df918a443051ec6ec2e9073c Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Mon, 5 Sep 2016 14:50:11 -0700 Subject: Issue #24254: Preserve class attribute definition order. --- Lib/test/test_types.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'Lib/test/test_types.py') diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index a202196bd2..e5e110f9c2 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -825,6 +825,28 @@ class ClassCreationTests(unittest.TestCase): self.assertEqual(C.y, 1) self.assertEqual(C.z, 2) + def test_new_class_deforder(self): + C = types.new_class("C") + self.assertEqual(C.__definition_order__, tuple()) + + Meta = self.Meta + def func(ns): + ns["x"] = 0 + D = types.new_class("D", (), {"metaclass": Meta, "z": 2}, func) + self.assertEqual(D.__definition_order__, ('y', 'z', 'x')) + + def func(ns): + ns["__definition_order__"] = None + ns["x"] = 0 + D = types.new_class("D", (), {"metaclass": Meta, "z": 2}, func) + self.assertEqual(D.__definition_order__, None) + + def func(ns): + ns["__definition_order__"] = ('a', 'b', 'c') + ns["x"] = 0 + D = types.new_class("D", (), {"metaclass": Meta, "z": 2}, func) + self.assertEqual(D.__definition_order__, ('a', 'b', 'c')) + # Many of the following tests are derived from test_descr.py def test_prepare_class(self): # Basic test of metaclass derivation -- cgit v1.2.1 From 761928cf31626534ebb81a6326c61b42050ef388 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 8 Sep 2016 15:11:11 -0700 Subject: Issue #24254: Drop cls.__definition_order__. --- Lib/test/test_types.py | 22 ---------------------- 1 file changed, 22 deletions(-) (limited to 'Lib/test/test_types.py') diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index e5e110f9c2..a202196bd2 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -825,28 +825,6 @@ class ClassCreationTests(unittest.TestCase): self.assertEqual(C.y, 1) self.assertEqual(C.z, 2) - def test_new_class_deforder(self): - C = types.new_class("C") - self.assertEqual(C.__definition_order__, tuple()) - - Meta = self.Meta - def func(ns): - ns["x"] = 0 - D = types.new_class("D", (), {"metaclass": Meta, "z": 2}, func) - self.assertEqual(D.__definition_order__, ('y', 'z', 'x')) - - def func(ns): - ns["__definition_order__"] = None - ns["x"] = 0 - D = types.new_class("D", (), {"metaclass": Meta, "z": 2}, func) - self.assertEqual(D.__definition_order__, None) - - def func(ns): - ns["__definition_order__"] = ('a', 'b', 'c') - ns["x"] = 0 - D = types.new_class("D", (), {"metaclass": Meta, "z": 2}, func) - self.assertEqual(D.__definition_order__, ('a', 'b', 'c')) - # Many of the following tests are derived from test_descr.py def test_prepare_class(self): # Basic test of metaclass derivation -- cgit v1.2.1 From 033712922fc31dd53c74ed2d299f81b969ae7e98 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Fri, 9 Sep 2016 14:57:09 -0700 Subject: Issue #26331: Implement the parsing part of PEP 515. Thanks to Georg Brandl for the patch. --- Lib/test/test_types.py | 1 + 1 file changed, 1 insertion(+) (limited to 'Lib/test/test_types.py') diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py index a202196bd2..382ca03e5a 100644 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@ -48,6 +48,7 @@ class TypesTests(unittest.TestCase): def test_float_constructor(self): self.assertRaises(ValueError, float, '') self.assertRaises(ValueError, float, '5\0') + self.assertRaises(ValueError, float, '5_5\0') def test_zero_division(self): try: 5.0 / 0.0 -- cgit v1.2.1