Compilers should be static when they're just functions; when they're callable objects, they control their own instance of 'self'.

This commit is contained in:
Elf M. Sternberg 2016-07-09 17:46:21 -07:00
parent 0cfa023bc1
commit c5f63db5f0
2 changed files with 7 additions and 4 deletions

View File

@ -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

View File

@ -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")