diff -r 19488e23dcdb Lib/ctypes/test/test_structures.py --- a/Lib/ctypes/test/test_structures.py Fri Jun 03 10:48:43 2016 +0300 +++ b/Lib/ctypes/test/test_structures.py Fri Jun 03 10:36:15 2016 -0700 @@ -320,14 +320,14 @@ cls, msg = self.get_except(Person, b"Someone", (1, 2)) self.assertEqual(cls, RuntimeError) - self.assertEqual(msg, - "(Phone) : " - "expected bytes, int found") + self.assertRegex(msg, + r"\(Phone\) : " + r"expected bytes, int found") cls, msg = self.get_except(Person, b"Someone", (b"a", b"b", b"c")) self.assertEqual(cls, RuntimeError) - self.assertEqual(msg, - "(Phone) : too many initializers") + self.assertRegex(msg, + r"\(Phone\) : too many initializers") def test_huge_field_name(self): # issue12881: segfault with large structure field names diff -r 19488e23dcdb Lib/statistics.py --- a/Lib/statistics.py Fri Jun 03 10:48:43 2016 +0300 +++ b/Lib/statistics.py Fri Jun 03 10:36:15 2016 -0700 @@ -131,23 +131,23 @@ -------- >>> _sum([3, 2.25, 4.5, -0.5, 1.0], 0.75) - (, Fraction(11, 1), 5) + (, Fraction(11, 1), 5) Some sources of round-off error will be avoided: >>> _sum([1e50, 1, -1e50] * 1000) # Built-in sum returns zero. - (, Fraction(1000, 1), 3000) + (, Fraction(1000, 1), 3000) Fractions and Decimals are also supported: >>> from fractions import Fraction as F >>> _sum([F(2, 3), F(7, 5), F(1, 4), F(5, 6)]) - (, Fraction(63, 20), 4) + (, Fraction(63, 20), 4) >>> from decimal import Decimal as D >>> data = [D("0.1375"), D("0.2108"), D("0.3061"), D("0.0419")] >>> _sum(data) - (, Fraction(6963, 10000), 4) + (, Fraction(6963, 10000), 4) Mixed types are currently treated as an error, except that int is allowed. diff -r 19488e23dcdb Lib/test/test_class.py --- a/Lib/test/test_class.py Fri Jun 03 10:48:43 2016 +0300 +++ b/Lib/test/test_class.py Fri Jun 03 10:36:15 2016 -0700 @@ -568,5 +568,15 @@ a = A(hash(A.f)^(-1)) hash(a.f) + def test_class_repr(self): + # We should get the address of the object + class A: + pass + + result = repr(A) + self.assertRegex(result, + ".A'" + " at 0x.+>") + if __name__ == '__main__': unittest.main() diff -r 19488e23dcdb Lib/test/test_cmd_line_script.py --- a/Lib/test/test_cmd_line_script.py Fri Jun 03 10:48:43 2016 +0300 +++ b/Lib/test/test_cmd_line_script.py Fri Jun 03 10:36:15 2016 -0700 @@ -127,7 +127,10 @@ print(printed_package) print(printed_argv0) print(printed_cwd) - self.assertIn(printed_loader.encode('utf-8'), data) + expected = printed_loader.encode('utf-8') + idx = expected.find(b"at 0x") + expected = expected[:idx] + self.assertIn(expected, data) self.assertIn(printed_file.encode('utf-8'), data) self.assertIn(printed_package.encode('utf-8'), data) self.assertIn(printed_argv0.encode('utf-8'), data) @@ -158,6 +161,8 @@ def test_dash_c_loader(self): rc, out, err = assert_python_ok("-c", "print(__loader__)") expected = repr(importlib.machinery.BuiltinImporter).encode("utf-8") + idx = expected.find(b"at 0x") + expected = expected[:idx] self.assertIn(expected, out) def test_stdin_loader(self): @@ -171,6 +176,8 @@ finally: out = kill_python(p) expected = repr(importlib.machinery.BuiltinImporter).encode("utf-8") + idx = expected.find(b"at 0x") + expected = expected[:idx] self.assertIn(expected, out) @contextlib.contextmanager diff -r 19488e23dcdb Lib/test/test_defaultdict.py --- a/Lib/test/test_defaultdict.py Fri Jun 03 10:48:43 2016 +0300 +++ b/Lib/test/test_defaultdict.py Fri Jun 03 10:36:15 2016 -0700 @@ -65,7 +65,7 @@ d2 = defaultdict(int) self.assertEqual(d2.default_factory, int) d2[12] = 42 - self.assertEqual(repr(d2), "defaultdict(, {12: 42})") + self.assertRegex(repr(d2), r"defaultdict\(, {12: 42}\)") def foo(): return 43 d3 = defaultdict(foo) self.assertTrue(d3.default_factory is foo) diff -r 19488e23dcdb Lib/test/test_descr.py --- a/Lib/test/test_descr.py Fri Jun 03 10:48:43 2016 +0300 +++ b/Lib/test/test_descr.py Fri Jun 03 10:36:15 2016 -0700 @@ -4544,9 +4544,9 @@ pass foo = Foo() self.assertRegex(repr(foo.method), # access via instance - r">") + r">") self.assertRegex(repr(Foo.method), # access via the class - r">") + r">") class MyCallable: diff -r 19488e23dcdb Lib/test/test_descrtut.py --- a/Lib/test/test_descrtut.py Fri Jun 03 10:48:43 2016 +0300 +++ b/Lib/test/test_descrtut.py Fri Jun 03 10:36:15 2016 -0700 @@ -37,16 +37,16 @@ Here's the new type at work: >>> print(defaultdict) # show our type - + >>> print(type(defaultdict)) # its metatype - + >>> a = defaultdict(default=0.0) # create an instance >>> print(a) # show the instance {} >>> print(type(a)) # show its type - + >>> print(a.__class__) # show its class - + >>> print(type(a) is a.__class__) # its type is its class True >>> a[1] = 3.25 # modify the instance @@ -149,11 +149,11 @@ For instance of built-in types, x.__class__ is now the same as type(x): >>> type([]) - + >>> [].__class__ - + >>> list - + >>> isinstance([], list) True >>> isinstance([], dict) @@ -258,19 +258,19 @@ ... print("classmethod", cls, y) >>> C.foo(1) - classmethod 1 + classmethod 1 >>> c = C() >>> c.foo(1) - classmethod 1 + classmethod 1 >>> class D(C): ... pass >>> D.foo(1) - classmethod 1 + classmethod 1 >>> d = D() >>> d.foo(1) - classmethod 1 + classmethod 1 This prints "classmethod __main__.D 1" both times; in other words, the class passed as the first argument of foo() is the class involved in the @@ -286,11 +286,11 @@ >>> E.foo(1) E.foo() called - classmethod 1 + classmethod 1 >>> e = E() >>> e.foo(1) E.foo() called - classmethod 1 + classmethod 1 In this example, the call to C.foo() from E.foo() will see class C as its first argument, not class E. This is to be expected, since the call @@ -350,7 +350,7 @@ >>> del property # unmask the builtin >>> property - + >>> class C(object): ... def __init__(self): @@ -478,7 +478,8 @@ # business is used the name can change depending on how the test is # invoked. from test import support, test_descrtut - support.run_doctest(test_descrtut, verbose) + import doctest + support.run_doctest(test_descrtut, verbose, optionflags=doctest.ELLIPSIS) # This part isn't needed for regrtest, but for running the test directly. if __name__ == "__main__": diff -r 19488e23dcdb Lib/test/test_doctest.py --- a/Lib/test/test_doctest.py Fri Jun 03 10:48:43 2016 +0300 +++ b/Lib/test/test_doctest.py Fri Jun 03 10:36:15 2016 -0700 @@ -2338,7 +2338,7 @@ `__file__` global, which is set to the name of the file containing the tests: - >>> suite = doctest.DocFileSuite('test_doctest3.txt') + >>> suite = doctest.DocFileSuite('test_doctest3.txt', optionflags=doctest.ELLIPSIS) >>> suite.run(unittest.TestResult()) diff -r 19488e23dcdb Lib/test/test_doctest3.txt --- a/Lib/test/test_doctest3.txt Fri Jun 03 10:48:43 2016 +0300 +++ b/Lib/test/test_doctest3.txt Fri Jun 03 10:36:15 2016 -0700 @@ -2,4 +2,4 @@ Here we check that `__file__` is provided: >>> type(__file__) - + diff -r 19488e23dcdb Lib/test/test_functools.py --- a/Lib/test/test_functools.py Fri Jun 03 10:48:43 2016 +0300 +++ b/Lib/test/test_functools.py Fri Jun 03 10:36:15 2016 -0700 @@ -1697,13 +1697,10 @@ c.Container.register(P) with self.assertRaises(RuntimeError) as re_one: g(p) - self.assertIn( - str(re_one.exception), - (("Ambiguous dispatch: " - "or "), - ("Ambiguous dispatch: " - "or ")), - ) + self.assertIn("Ambiguous dispatch:", str(re_one.exception)) + self.assertIn(" " - "or "), - ("Ambiguous dispatch: " - "or ")), - ) + self.assertIn("Ambiguous dispatch:", str(re_two.exception)) + self.assertIn(" " - "or "), - ("Ambiguous dispatch: " - "or ")), - ) + self.assertIn("Ambiguous dispatch:", str(re_three.exception)) + self.assertIn(">> type(g) - + >>> i = g() >>> type(i) - + >>> [s for s in dir(i) if not s.startswith('_')] ['close', 'gi_code', 'gi_frame', 'gi_running', 'gi_yieldfrom', 'send', 'throw'] >>> from test.support import HAVE_DOCSTRINGS @@ -691,7 +691,7 @@ >>> i.gi_running 0 >>> type(i.gi_frame) - + >>> i.gi_running = 42 Traceback (most recent call last): ... @@ -1066,27 +1066,27 @@ >>> def f(): ... yield >>> type(f()) - + >>> def f(): ... if 0: ... yield >>> type(f()) - + >>> def f(): ... if 0: ... yield 1 >>> type(f()) - + >>> def f(): ... if "": ... yield None >>> type(f()) - + >>> def f(): ... return @@ -1110,7 +1110,7 @@ ... x = 1 ... return >>> type(f()) - + >>> def f(): ... if 0: @@ -1118,7 +1118,7 @@ ... yield 1 ... >>> type(f()) - + >>> def f(): ... if 0: @@ -1128,7 +1128,7 @@ ... def f(self): ... yield 2 >>> type(f()) - + >>> def f(): ... if 0: @@ -1136,7 +1136,7 @@ ... if 0: ... yield 2 >>> type(f()) - + This one caused a crash (see SF bug 567538): @@ -1791,7 +1791,7 @@ >>> def f(): list(i for i in [(yield 26)]) >>> type(f()) - + A yield expression with augmented assignment. @@ -2047,25 +2047,25 @@ >>> def f(): x += yield >>> type(f()) - + >>> def f(): x = yield >>> type(f()) - + >>> def f(): lambda x=(yield): 1 >>> type(f()) - + >>> def f(): x=(i for i in (yield) if (yield)) >>> type(f()) - + >>> def f(d): d[(yield "a")] = d[(yield "b")] = 27 >>> data = [1,2] >>> g = f(data) >>> type(g) - + >>> g.send(None) 'a' >>> data @@ -2174,8 +2174,9 @@ # so this works as expected in both ways of running regrtest. def test_main(verbose=None): from test import support, test_generators + import doctest support.run_unittest(__name__) - support.run_doctest(test_generators, verbose) + support.run_doctest(test_generators, verbose, optionflags=doctest.ELLIPSIS) # This part isn't needed for regrtest, but for running the test directly. if __name__ == "__main__": diff -r 19488e23dcdb Lib/test/test_genexps.py --- a/Lib/test/test_genexps.py Fri Jun 03 10:48:43 2016 +0300 +++ b/Lib/test/test_genexps.py Fri Jun 03 10:36:15 2016 -0700 @@ -27,7 +27,7 @@ >>> g = (i*i for i in range(4)) >>> type(g) - + >>> list(g) [0, 1, 4, 9] @@ -269,7 +269,8 @@ def test_main(verbose=None): from test import support from test import test_genexps - support.run_doctest(test_genexps, verbose) + import doctest + support.run_doctest(test_genexps, verbose, optionflags=doctest.ELLIPSIS) # verify reference counting if verbose and hasattr(sys, "gettotalrefcount"): diff -r 19488e23dcdb Lib/test/test_metaclass.py --- a/Lib/test/test_metaclass.py Fri Jun 03 10:48:43 2016 +0300 +++ b/Lib/test/test_metaclass.py Fri Jun 03 10:36:15 2016 -0700 @@ -78,7 +78,7 @@ >>> class C(object, metaclass=M, other="haha"): ... pass ... - Prepare called: ('C', (,)) {'other': 'haha'} + Prepare called: ('C', (,)) {'other': 'haha'} New called: {'other': 'haha'} >>> C.__class__ is M True @@ -104,7 +104,7 @@ >>> kwds = {'metaclass': M, 'other': 'haha'} >>> class C(*bases, **kwds): pass ... - Prepare called: ('C', (,)) {'other': 'haha'} + Prepare called: ('C', (,)) {'other': 'haha'} New called: {'other': 'haha'} >>> C.__class__ is M True @@ -114,7 +114,7 @@ >>> kwds = {'other': 'haha'} >>> class C(B, metaclass=M, *bases, **kwds): pass ... - Prepare called: ('C', (, )) {'other': 'haha'} + Prepare called: ('C', (, )) {'other': 'haha'} New called: {'other': 'haha'} >>> C.__class__ is M True @@ -259,7 +259,8 @@ def test_main(verbose=False): from test import support from test import test_metaclass - support.run_doctest(test_metaclass, verbose) + import doctest + support.run_doctest(test_metaclass, verbose, optionflags=doctest.ELLIPSIS) if __name__ == "__main__": test_main(verbose=True) diff -r 19488e23dcdb Lib/test/test_pprint.py --- a/Lib/test/test_pprint.py Fri Jun 03 10:48:43 2016 +0300 +++ b/Lib/test/test_pprint.py Fri Jun 03 10:36:15 2016 -0700 @@ -848,12 +848,11 @@ def test_default_dict(self): d = collections.defaultdict(int) - self.assertEqual(pprint.pformat(d, width=1), "defaultdict(, {})") + self.assertRegex(pprint.pformat(d, width=1), r"defaultdict\(, {}\)") words = 'the quick brown fox jumped over a lazy dog'.split() d = collections.defaultdict(int, zip(words, itertools.count())) - self.assertEqual(pprint.pformat(d), -"""\ -defaultdict(, + self.assertRegex(pprint.pformat(d), +r"""defaultdict\(, {'a': 6, 'brown': 2, 'dog': 8, @@ -862,7 +861,7 @@ 'lazy': 7, 'over': 5, 'quick': 1, - 'the': 0})""") + 'the': 0}\)""") def test_counter(self): d = collections.Counter() diff -r 19488e23dcdb Lib/test/test_reprlib.py --- a/Lib/test/test_reprlib.py Fri Jun 03 10:48:43 2016 +0300 +++ b/Lib/test/test_reprlib.py Fri Jun 03 10:36:15 2016 -0700 @@ -292,8 +292,8 @@ ''') importlib.invalidate_caches() from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import foo - eq(repr(foo.foo), - "" % foo.__name__) + self.assertRegex(repr(foo.foo), + r"" % foo.__name__) @unittest.skip('need a suitable object') def test_object(self): @@ -310,7 +310,7 @@ importlib.invalidate_caches() from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import bar # Module name may be prefixed with "test.", depending on how run. - self.assertEqual(repr(bar.bar), "" % bar.__name__) + self.assertRegex(repr(bar.bar), r"" % bar.__name__) def test_instance(self): self._check_path_limitations('baz') diff -r 19488e23dcdb Lib/test/test_statistics.py --- a/Lib/test/test_statistics.py Fri Jun 03 10:48:43 2016 +0300 +++ b/Lib/test/test_statistics.py Fri Jun 03 10:36:15 2016 -0700 @@ -659,7 +659,7 @@ @unittest.skipIf(sys.flags.optimize >= 2, "Docstrings are omitted with -OO and above") def test_doc_tests(self): - failed, tried = doctest.testmod(statistics) + failed, tried = doctest.testmod(statistics, optionflags=doctest.ELLIPSIS) self.assertGreater(tried, 0) self.assertEqual(failed, 0) diff -r 19488e23dcdb Lib/test/test_wsgiref.py --- a/Lib/test/test_wsgiref.py Fri Jun 03 10:48:43 2016 +0300 +++ b/Lib/test/test_wsgiref.py Fri Jun 03 10:36:15 2016 -0700 @@ -161,10 +161,10 @@ self.assertTrue(out.endswith( b"A server error occurred. Please contact the administrator." )) - self.assertEqual( + self.assertRegex( err.splitlines()[-2], - "AssertionError: Headers (('Content-Type', 'text/plain')) must" - " be of type list: " + r"AssertionError: Headers \(\('Content-Type', 'text/plain'\)\) must" + r" be of type list: " ) def test_status_validation_errors(self): @@ -704,3 +704,4 @@ if __name__ == "__main__": unittest.main() + diff -r 19488e23dcdb Lib/test/test_xmlrpc.py --- a/Lib/test/test_xmlrpc.py Fri Jun 03 10:48:43 2016 +0300 +++ b/Lib/test/test_xmlrpc.py Fri Jun 03 10:36:15 2016 -0700 @@ -775,8 +775,8 @@ # 'method "this_is_not_exists" is not supported'>}] self.assertEqual(result.results[0]['faultCode'], 1) - self.assertEqual(result.results[0]['faultString'], - ':method "this_is_not_exists" ' + self.assertRegex(result.results[0]['faultString'], + ':method "this_is_not_exists" ' 'is not supported') except (xmlrpclib.ProtocolError, OSError) as e: # ignore failures due to non-blocking socket 'unavailable' errors diff -r 19488e23dcdb Misc/NEWS --- a/Misc/NEWS Fri Jun 03 10:48:43 2016 +0300 +++ b/Misc/NEWS Fri Jun 03 10:36:15 2016 -0700 @@ -50,6 +50,8 @@ - Issue #21271: New keyword only parameters in reset_mock call. +- Issue #25548: Showing memory address of class objects in repl. + IDLE ---- diff -r 19488e23dcdb Objects/typeobject.c --- a/Objects/typeobject.c Fri Jun 03 10:48:43 2016 +0300 +++ b/Objects/typeobject.c Fri Jun 03 10:36:15 2016 -0700 @@ -859,9 +859,9 @@ } if (mod != NULL && _PyUnicode_CompareWithId(mod, &PyId_builtins)) - rtn = PyUnicode_FromFormat("", mod, name); - else - rtn = PyUnicode_FromFormat("", type->tp_name); + rtn = PyUnicode_FromFormat("", mod, name, type); + else + rtn = PyUnicode_FromFormat("", type->tp_name, type); Py_XDECREF(mod); Py_DECREF(name);