From: Serhiy Storchaka Date: Fri, 22 May 2015 08:13:20 +0000 (+0300) Subject: Issue #24257: Fixed incorrect uses of PyObject_IsInstance(). X-Git-Tag: v3.5.0b1~42 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e79ec70801e410de9c3110ffe78f98e08114ae16;p=python Issue #24257: Fixed incorrect uses of PyObject_IsInstance(). Fixed segmentation fault in sqlite3.Row constructor with faked cursor type. Fixed system error in the comparison of faked types.SimpleNamespace. --- e79ec70801e410de9c3110ffe78f98e08114ae16 diff --cc Lib/test/test_types.py index c5a35f9e7e,849cba9649..ccaf414c44 --- a/Lib/test/test_types.py +++ b/Lib/test/test_types.py @@@ -1172,38 -1169,26 +1172,54 @@@ class SimpleNamespaceTests(unittest.Tes self.assertEqual(ns, ns_roundtrip, pname) + def test_fake_namespace_compare(self): + # Issue #24257: Incorrect use of PyObject_IsInstance() caused + # SystemError. + class FakeSimpleNamespace(str): + __class__ = types.SimpleNamespace + self.assertFalse(types.SimpleNamespace() == FakeSimpleNamespace()) + self.assertTrue(types.SimpleNamespace() != FakeSimpleNamespace()) + with self.assertRaises(TypeError): + types.SimpleNamespace() < FakeSimpleNamespace() + with self.assertRaises(TypeError): + types.SimpleNamespace() <= FakeSimpleNamespace() + with self.assertRaises(TypeError): + types.SimpleNamespace() > FakeSimpleNamespace() + with self.assertRaises(TypeError): + types.SimpleNamespace() >= FakeSimpleNamespace() + -def test_main(): - run_unittest(TypesTests, MappingProxyTests, ClassCreationTests, - SimpleNamespaceTests) +class CoroutineTests(unittest.TestCase): + def test_wrong_args(self): + class Foo: + def __call__(self): + pass + def bar(): pass + + samples = [Foo, Foo(), bar, None, int, 1] + for sample in samples: + with self.assertRaisesRegex(TypeError, 'expects a generator'): + types.coroutine(sample) + + def test_genfunc(self): + def gen(): + yield + + self.assertFalse(isinstance(gen(), collections.abc.Coroutine)) + self.assertFalse(isinstance(gen(), collections.abc.Awaitable)) + + self.assertIs(types.coroutine(gen), gen) + + self.assertTrue(gen.__code__.co_flags & inspect.CO_ITERABLE_COROUTINE) + self.assertFalse(gen.__code__.co_flags & inspect.CO_COROUTINE) + + g = gen() + self.assertTrue(g.gi_code.co_flags & inspect.CO_ITERABLE_COROUTINE) + self.assertFalse(g.gi_code.co_flags & inspect.CO_COROUTINE) + self.assertTrue(isinstance(g, collections.abc.Coroutine)) + self.assertTrue(isinstance(g, collections.abc.Awaitable)) + g.close() # silence warning + if __name__ == '__main__': - test_main() + unittest.main() diff --cc Misc/NEWS index 1fa52a616e,6b491d003a..891b61ebf3 --- a/Misc/NEWS +++ b/Misc/NEWS @@@ -55,17 -59,9 +58,20 @@@ Core and Builtin Library ------- + - Issue #24257: Fixed segmentation fault in sqlite3.Row constructor with faked + cursor type. + +- Issue #15836: assertRaises(), assertRaisesRegex(), assertWarns() and + assertWarnsRegex() assertments now check the type of the first argument + to prevent possible user error. Based on patch by Daniel Wagner-Hall. + +- Issue #9858: Add missing method stubs to _io.RawIOBase. Patch by Laura + Rupprecht. + +- Issue #22955: attrgetter, itemgetter and methodcaller objects in the operator + module now support pickling. Added readable and evaluable repr for these + objects. Based on patch by Josh Rosenberg. + - Issue #22107: tempfile.gettempdir() and tempfile.mkdtemp() now try again when a directory with the chosen name already exists on Windows as well as on Unix. tempfile.mkstemp() now fails early if parent directory is not