[Python-checkins] cpython: Issue #18864: Add a setter for ModuleSpec.has_location.

eric.snow python-checkins at python.org
Wed Dec 11 06:17:21 CET 2013


http://hg.python.org/cpython/rev/e961a166dc70
changeset: 87898:e961a166dc70
user: Eric Snow <ericsnowcurrently at gmail.com>
date: Tue Dec 10 22:16:41 2013 -0700
summary:
 Issue #18864: Add a setter for ModuleSpec.has_location.
files:
 Doc/library/importlib.rst | 2 +-
 Lib/importlib/_bootstrap.py | 4 +
 Lib/test/test_importlib/test_spec.py | 7 +
 Misc/NEWS | 2 +
 Python/importlib.h | 5849 +++++++------
 5 files changed, 2943 insertions(+), 2921 deletions(-)
diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst
--- a/Doc/library/importlib.rst
+++ b/Doc/library/importlib.rst
@@ -901,7 +901,7 @@
 
 .. attribute:: has_location
 
- (Read-only) Boolean indicating whether or not the module's "origin"
+ Boolean indicating whether or not the module's "origin"
 attribute refers to a loadable location.
 
 :mod:`importlib.util` -- Utility code for importers
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -841,6 +841,10 @@
 def has_location(self):
 return self._set_fileattr
 
+ @has_location.setter
+ def has_location(self, value):
+ self._set_fileattr = bool(value)
+
 
 def spec_from_loader(name, loader, *, origin=None, is_package=None):
 """Return a module spec based on various loader methods."""
diff --git a/Lib/test/test_importlib/test_spec.py b/Lib/test/test_importlib/test_spec.py
--- a/Lib/test/test_importlib/test_spec.py
+++ b/Lib/test/test_importlib/test_spec.py
@@ -116,6 +116,13 @@
 self.assertIs(spec.cached, None)
 self.assertFalse(spec.has_location)
 
+ def test_has_location_setter(self):
+ spec = self.machinery.ModuleSpec(self.name, self.loader,
+ origin='somewhere')
+ self.assertFalse(spec.has_location)
+ spec.has_location = True
+ self.assertTrue(spec.has_location)
+
 def test_equality(self):
 other = type(sys.implementation)(name=self.name,
 loader=self.loader,
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -105,6 +105,8 @@
 - Issue #19698: Removed exec_module() methods from
 importlib.machinery.BuiltinImporter and ExtensionFileLoader.
 
+- Issue #18864: Added a setter for ModuleSpec.has_location.
+
 - Fixed _pickle.Unpickler to not fail when loading empty strings as
 persistent IDs.
 
diff --git a/Python/importlib.h b/Python/importlib.h
--- a/Python/importlib.h
+++ b/Python/importlib.h
[stripped]
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /