From e76c0393a8dc35af38d6d2af2827f405a7ef6116 Mon Sep 17 00:00:00 2001 From: David Wolever Date: Wed, 14 Aug 2013 14:41:48 -0400 Subject: [PATCH 1/2] Remove errant fourth '.' from ellipsis in datetime documentation. --- Doc/library/datetime.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst index 27885f9544d..30b63e1d98c 100644 --- a/Doc/library/datetime.rst +++ b/Doc/library/datetime.rst @@ -1406,7 +1406,7 @@ Instance methods: Return a string representing the time, controlled by an explicit format string. For a complete list of formatting directives, see - :ref:`strftime-strptime-behavior`. + :ref:`strftime-strptime-behavior`. .. method:: time.__format__(format) @@ -1826,7 +1826,7 @@ format codes. | | zero-padded decimal number. | | | +-----------+--------------------------------+------------------------+-------+ | ``%Y`` | Year with century as a decimal | 0001, 0002, ..., 2013, | \(2) | -| | number. | 2014, ...., 9998, 9999 | | +| | number. | 2014, ..., 9998, 9999 | | +-----------+--------------------------------+------------------------+-------+ | ``%H`` | Hour (24-hour clock) as a | 00, 01, ..., 23 | | | | zero-padded decimal number. | | | From 7491f1726ba3a5f78beddca2280f9141d559ff1c Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Wed, 14 Aug 2013 18:03:34 -0600 Subject: [PATCH 2/2] issue #18698: ensure importlib.reload() returns the module out of sys.modules. --- Lib/imp.py | 4 +++- Lib/test/test_imp.py | 17 +++++++++++++++++ Misc/NEWS | 2 ++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Lib/imp.py b/Lib/imp.py index 34b6c542e12..30c343f62e0 100644 --- a/Lib/imp.py +++ b/Lib/imp.py @@ -268,7 +268,9 @@ def reload(module): if parent_name and parent_name not in sys.modules: msg = "parent {!r} not in sys.modules" raise ImportError(msg.format(parent_name), name=parent_name) - return module.__loader__.load_module(name) + module.__loader__.load_module(name) + # The module may have replaced itself in sys.modules! + return sys.modules[module.__name__] finally: try: del _RELOADING[name] diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py index 3fb119bfc3f..bf29e424d24 100644 --- a/Lib/test/test_imp.py +++ b/Lib/test/test_imp.py @@ -5,6 +5,7 @@ import os.path import shutil import sys from test import support +from test.test_importlib import util import unittest import warnings @@ -285,6 +286,22 @@ class ReloadTests(unittest.TestCase): with self.assertRaisesRegex(ImportError, 'html'): imp.reload(parser) + def test_module_replaced(self): + # see #18698 + def code(): + module = type(sys)('top_level') + module.spam = 3 + sys.modules['top_level'] = module + mock = util.mock_modules('top_level', + module_code={'top_level': code}) + with mock: + with util.import_state(meta_path=[mock]): + module = importlib.import_module('top_level') + reloaded = imp.reload(module) + actual = sys.modules['top_level'] + self.assertEqual(actual.spam, 3) + self.assertEqual(reloaded.spam, 3) + class PEP3147Tests(unittest.TestCase): """Tests of PEP 3147.""" diff --git a/Misc/NEWS b/Misc/NEWS index 7a4491aa3a8..0dd2d1099ba 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -202,6 +202,8 @@ Library - Issue #17269: Workaround for socket.getaddrinfo crash on MacOS X with port None or "0" and flags AI_NUMERICSERV. +- Issue #18698: Ensure imp.reload() returns the module out of sys.modules. + - Issue #18080: When building a C extension module on OS X, if the compiler is overriden with the CC environment variable, use the new compiler as the default for linking if LDSHARED is not also overriden. This restores