cpython: e39a8f8ceb9f (original) (raw)

--- a/Doc/c-api/module.rst +++ b/Doc/c-api/module.rst @@ -35,13 +35,20 @@ There are only a few functions special t single: name (module attribute) single: doc (module attribute) single: file (module attribute)

Return a new module object with the :attr:__name__ attribute set to name.

+ .. c:function:: PyObject* PyModule_New(const char *name)

--- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -827,7 +827,7 @@ an :term:importer. decorator as it subsumes this functionality. .. versionchanged:: 3.4

--- a/Doc/reference/import.rst +++ b/Doc/reference/import.rst @@ -423,8 +423,8 @@ Here are the exact rules used:

--- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -231,3 +231,8 @@ that may require changes to your code. :exc:NotImplementedError blindly. This will only affect code calling :func:super and falling through all the way to the ABCs. For compatibility, catch both :exc:NotImplementedError or the appropriate exception as needed. + +* The module type now initializes the :attr:__package__ and :attr:__loader__

--- a/Lib/ctypes/test/init.py +++ b/Lib/ctypes/test/init.py @@ -37,7 +37,7 @@ def requires(resource, msg=None): def find_package_modules(package, mask): import fnmatch

--- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -215,7 +215,7 @@ def _load_testfile(filename, package, mo if module_relative: package = _normalize_module(package, 3) filename = _module_relative_path(package, filename)

--- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -1726,7 +1726,7 @@ def _setup(sys_module, _imp_module): module_type = type(sys) for name, module in sys.modules.items(): if isinstance(module, module_type):

--- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -476,7 +476,7 @@ def getsourcefile(object): if os.path.exists(filename): return filename # only return a non-existent filename if the module has a PEP 302 loader

--- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -2250,7 +2250,9 @@ order (MRO) for bases """ minstance = M("m") minstance.b = 2 minstance.a = 1

class M2(M):

--- a/Lib/test/test_importlib/test_api.py +++ b/Lib/test/test_importlib/test_api.py @@ -197,14 +197,12 @@ class StartupTests(unittest.TestCase): # Issue #17098: all modules should have loader defined. for name, module in sys.modules.items(): if isinstance(module, types.ModuleType):

if name == 'main':

--- a/Lib/test/test_module.py +++ b/Lib/test/test_module.py @@ -33,7 +33,10 @@ class ModuleTests(unittest.TestCase): foo = ModuleType("foo") self.assertEqual(foo.name, "foo") self.assertEqual(foo.doc, None)

def test_ascii_docstring(self): # ASCII docstring @@ -41,7 +44,8 @@ class ModuleTests(unittest.TestCase): self.assertEqual(foo.name, "foo") self.assertEqual(foo.doc, "foodoc") self.assertEqual(foo.dict,

def test_unicode_docstring(self): # Unicode docstring @@ -49,7 +53,8 @@ class ModuleTests(unittest.TestCase): self.assertEqual(foo.name, "foo") self.assertEqual(foo.doc, "foodoc\u1234") self.assertEqual(foo.dict,

def test_reinit(self): # Reinitialization should not replace the dict @@ -61,7 +66,8 @@ class ModuleTests(unittest.TestCase): self.assertEqual(foo.doc, "foodoc") self.assertEqual(foo.bar, 42) self.assertEqual(foo.dict,

@unittest.expectedFailure @@ -110,13 +116,19 @@ a = A(destroyed)""" m.file = '/tmp/foo.py' self.assertEqual(repr(m), "<module '?' from '/tmp/foo.py'>")

+ def test_module_repr_with_bare_loader_but_no_name(self): m = ModuleType('foo') del m.name # Yes, a class not an instance. m.loader = BareLoader

def test_module_repr_with_full_loader_but_no_name(self): # m.loader.module_repr() will fail because the module has no @@ -126,15 +138,17 @@ a = A(destroyed)""" del m.name # Yes, a class not an instance. m.loader = FullLoader

def test_module_repr_with_bare_loader(self): m = ModuleType('foo') # Yes, a class not an instance. m.loader = BareLoader

def test_module_repr_with_full_loader(self): m = ModuleType('foo')

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ What's New in Python 3.4.0 Alpha 1? Core and Builtins ----------------- +- Issue #17115,17116: Module initialization now includes setting package and

--- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -26,6 +26,27 @@ static PyTypeObject moduledef_type = { }; +static int +module_init_dict(PyObject *md_dict, PyObject *name, PyObject *doc) +{

+

+

+} + + PyObject * PyModule_NewObject(PyObject *name) { @@ -36,13 +57,7 @@ PyModule_NewObject(PyObject *name) m->md_def = NULL; m->md_state = NULL; m->md_dict = PyDict_New();

@@ -380,7 +393,7 @@ module_repr(PyModuleObject *m) if (m->md_dict != NULL) { loader = PyDict_GetItemString(m->md_dict, "loader"); }

@@ -404,10 +417,10 @@ module_repr(PyModuleObject *m) filename = PyModule_GetFilenameObject((PyObject *)m); if (filename == NULL) { PyErr_Clear();

--- a/Python/importlib.h +++ b/Python/importlib.h @@ -3354,189 +3354,190 @@ const unsigned char _Py_M__importlib[] = 115,26,0,0,0,0,11,12,1,15,2,24,1,12,1,18, 1,6,3,12,1,23,1,6,1,4,4,35,3,40,2,114, 77,1,0,0,99,2,0,0,0,0,0,0,0,16,0,0,

};

--- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -866,7 +866,8 @@ initmain(PyInterpreterState *interp) * be set if main gets further initialized later in the startup * process. */