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()
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