Issue #18864: Add a setter for ModuleSpec.has_location.

This commit is contained in:
Eric Snow 2013-12-10 22:16:41 -07:00
parent 85cce1eac7
commit b282b3d804
5 changed files with 2942 additions and 2920 deletions

View file

@ -901,7 +901,7 @@ find and load modules.
.. 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

View file

@ -841,6 +841,10 @@ def parent(self):
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."""

View file

@ -116,6 +116,13 @@ def test_default_is_package_true(self):
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,

View file

@ -105,6 +105,8 @@ Library
- 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.

File diff suppressed because it is too large Load diff