-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deal with a python 3.12 backwards compatibility break with meta_path …
…loaders. - also add python 3.12 to the testing framework
- Loading branch information
1 parent
6cc0633
commit f917112
Showing
3 changed files
with
31 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,12 @@ | |
import pickle | ||
import struct | ||
|
||
try: | ||
# only available (and needed) from 3.4 onwards. | ||
from importlib.machinery import ModuleSpec | ||
except: | ||
pass | ||
|
||
if PY3: | ||
from io import BytesIO as StringIO | ||
else: | ||
|
@@ -402,19 +408,38 @@ class FakePackageLoader(object): | |
this ensures that any attempt to get a submodule from module *root* | ||
results in a FakePackage, creating the illusion that *root* is an | ||
actual package tree. | ||
This class is both a `finder` and a `loader` | ||
""" | ||
def __init__(self, root): | ||
self.root = root | ||
|
||
# the old way of loading modules. find_module returns a loader for the | ||
# given module. In this case, that is this object itself again. | ||
|
||
def find_module(self, fullname, path=None): | ||
if fullname == self.root or fullname.startswith(self.root + "."): | ||
return self | ||
else: | ||
return None | ||
|
||
# the new way of loading modules. It returns a ModuleSpec, that has | ||
# the loader attribute set to this class. | ||
|
||
def find_spec(self, fullname, path, target=None): | ||
from importlib.machinery import ModuleSpec | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
CensoredUsername
Author
Owner
|
||
|
||
if fullname == self.root or fullname.startswith(self.root + "."): | ||
return ModuleSpec(fullname, self) | ||
else: | ||
return None | ||
|
||
# loader methods. This loads the module. | ||
|
||
def load_module(self, fullname): | ||
return FakePackage(fullname) | ||
|
||
|
||
# Fake unpickler implementation | ||
|
||
class FakeUnpicklingError(pickle.UnpicklingError): | ||
|
Already imported in the file-head in L34 where it belongs. Or did i miss the reason for the double import?