[Python-checkins] cpython: Issue #20884: whatsnew: Frozen modules don't set __file__ anymore.

brett.cannon python-checkins at python.org
Fri Mar 14 14:46:42 CET 2014


http://hg.python.org/cpython/rev/b626f4978a28
changeset:   89653:b626f4978a28
user:        Brett Cannon <brett at python.org>
date:        Fri Mar 14 09:46:28 2014 -0400
summary:
  Issue #20884: whatsnew: Frozen modules don't set __file__ anymore.

files:
  Doc/whatsnew/3.4.rst |  8 ++++++++
  1 files changed, 8 insertions(+), 0 deletions(-)


diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst
--- a/Doc/whatsnew/3.4.rst
+++ b/Doc/whatsnew/3.4.rst
@@ -2275,6 +2275,14 @@
   to determine if a module is a package or not is to use``hasattr(module,
   '__path__')`` (:issue:`18065`).
 
+* Frozen modules no longer define a ``__file__`` attribute. It's semantically
+  incorrect for frozen modules to set the attribute as they are not loaded from
+  any explicit location. If you must know that a module comes from frozen code
+  then you can see if the module's ``__spec__.location`` is set to ``'frozen'``,
+  check if the loader is a subclass of
+  :class:`importlib.machinery.FrozenImporter`,
+  or if Python 2 compatibility is necessary you can use :func:`imp.is_frozen`.
+
 * :func:`py_compile.compile` now raises :exc:`FileExistsError` if the file path
   it would write to is a symlink or a non-regular file. This is to act as a
   warning that import will overwrite those files with a regular file regardless

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list