Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b282b3d

Browse files
Issue #18864: Add a setter for ModuleSpec.has_location.
1 parent 85cce1e commit b282b3d

5 files changed

Lines changed: 2932 additions & 2910 deletions

File tree

Doc/library/importlib.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ find and load modules.
901901

902902
.. attribute:: has_location
903903

904-
(Read-only) Boolean indicating whether or not the module's "origin"
904+
Boolean indicating whether or not the module's "origin"
905905
attribute refers to a loadable location.
906906

907907
:mod:`importlib.util` -- Utility code for importers

Lib/importlib/_bootstrap.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,10 @@ def parent(self):
841841
def has_location(self):
842842
return self._set_fileattr
843843

844+
@has_location.setter
845+
def has_location(self, value):
846+
self._set_fileattr = bool(value)
847+
844848

845849
def spec_from_loader(name, loader, *, origin=None, is_package=None):
846850
"""Return a module spec based on various loader methods."""

Lib/test/test_importlib/test_spec.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ def test_default_is_package_true(self):
116116
self.assertIs(spec.cached, None)
117117
self.assertFalse(spec.has_location)
118118

119+
def test_has_location_setter(self):
120+
spec = self.machinery.ModuleSpec(self.name, self.loader,
121+
origin='somewhere')
122+
self.assertFalse(spec.has_location)
123+
spec.has_location = True
124+
self.assertTrue(spec.has_location)
125+
119126
def test_equality(self):
120127
other = type(sys.implementation)(name=self.name,
121128
loader=self.loader,

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ Library
105105
- Issue #19698: Removed exec_module() methods from
106106
importlib.machinery.BuiltinImporter and ExtensionFileLoader.
107107

108+
- Issue #18864: Added a setter for ModuleSpec.has_location.
109+
108110
- Fixed _pickle.Unpickler to not fail when loading empty strings as
109111
persistent IDs.
110112

0 commit comments

Comments
 (0)