Commit 69372db6 authored by Eric Snow's avatar Eric Snow

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

parent 9c5a7c2a
...@@ -901,7 +901,7 @@ find and load modules. ...@@ -901,7 +901,7 @@ find and load modules.
.. attribute:: has_location .. 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. attribute refers to a loadable location.
:mod:`importlib.util` -- Utility code for importers :mod:`importlib.util` -- Utility code for importers
......
...@@ -841,6 +841,10 @@ class ModuleSpec: ...@@ -841,6 +841,10 @@ class ModuleSpec:
def has_location(self): def has_location(self):
return self._set_fileattr 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): def spec_from_loader(name, loader, *, origin=None, is_package=None):
"""Return a module spec based on various loader methods.""" """Return a module spec based on various loader methods."""
......
...@@ -116,6 +116,13 @@ class ModuleSpecTests: ...@@ -116,6 +116,13 @@ class ModuleSpecTests:
self.assertIs(spec.cached, None) self.assertIs(spec.cached, None)
self.assertFalse(spec.has_location) 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): def test_equality(self):
other = type(sys.implementation)(name=self.name, other = type(sys.implementation)(name=self.name,
loader=self.loader, loader=self.loader,
......
...@@ -105,6 +105,8 @@ Library ...@@ -105,6 +105,8 @@ Library
- Issue #19698: Removed exec_module() methods from - Issue #19698: Removed exec_module() methods from
importlib.machinery.BuiltinImporter and ExtensionFileLoader. 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 - Fixed _pickle.Unpickler to not fail when loading empty strings as
persistent IDs. persistent IDs.
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment