]> granicus.if.org Git - python/commitdiff
Issue #24257: Fixed incorrect uses of PyObject_IsInstance().
authorSerhiy Storchaka <storchaka@gmail.com>
Fri, 22 May 2015 08:13:20 +0000 (11:13 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Fri, 22 May 2015 08:13:20 +0000 (11:13 +0300)
Fixed segmentation fault in sqlite3.Row constructor with faked cursor type.
Fixed system error in the comparison of faked types.SimpleNamespace.

1  2 
Lib/sqlite3/test/factory.py
Lib/test/test_types.py
Misc/NEWS
Modules/_sqlite/row.c
Objects/genobject.c

Simple merge
index c5a35f9e7e5df25cff85cdbb1d8757d3ced7e510,849cba9649609299830eedf7358212a25b54e8cb..ccaf414c4495ddb8962cacfbb603f96d518d120a
@@@ -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 1fa52a616ec5aad0bfce371bcc2f08fe35f2b826,6b491d003a356f8c3bb2e98d0b3d9d5a369f3f61..891b61ebf39492dc6f9cc9dbc35664223506b821
+++ 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
Simple merge
Simple merge