diff --git a/polyloader/_python3.py b/polyloader/_python3.py index dbbdb3d..08c4499 100644 --- a/polyloader/_python3.py +++ b/polyloader/_python3.py @@ -2,6 +2,7 @@ import os import sys import marshal import pkgutil +import types import _imp if sys.version_info[0:2] in [(3, 3), (3, 4)]: @@ -143,8 +144,12 @@ class PolyFileFinder(FileFinder): newloaderclassname = (suffixes[0].lower().capitalize() + str(_PolySourceFileLoader).rpartition('.')[2][1:]) - newloader = type(newloaderclassname, (_PolySourceFileLoader,), - dict(_compiler = compiler)) + if isinstance(compiler, types.FunctionType): + newloader = type(newloaderclassname, (_PolySourceFileLoader,), + dict(_compiler = staticmethod(compiler))) + else: + newloader = type(newloaderclassname, (_PolySourceFileLoader,), + dict(_compiler = compiler)) cls._custom_loaders += [(EXS + suffix, newloader) for suffix in suffixset] @classmethod @@ -208,7 +213,6 @@ class PolyFileFinder(FileFinder): def path_hook_for_PolyFileFinder(path): if not os.path.isdir(path): raise ImportError("only directories are supported", path=path) - print("Returning PolyFileFinder") return PolyFileFinder(path) return path_hook_for_PolyFileFinder diff --git a/tests_py3/test_polyloader.py b/tests_py3/test_polyloader.py index d2b787e..2f882aa 100644 --- a/tests_py3/test_polyloader.py +++ b/tests_py3/test_polyloader.py @@ -43,7 +43,6 @@ class Compiler: self.pt = pt def __call__(self, source_text, filename, *extra): - print(type(source_text)) return compile("result='Success for %s: %s'" % (self.pt, source_text.decode('utf-8').rstrip()), filename, "exec")