imp. is deprecated, use types.ModuleType instead

Thanks https://stackoverflow.com/a/32175781
This commit is contained in:
Simon Willison 2019-07-02 21:22:54 -07:00
commit dc893692fb

View file

@ -3,7 +3,6 @@ from collections import OrderedDict
import base64
import click
import hashlib
import imp
import json
import os
import pkg_resources
@ -11,6 +10,7 @@ import re
import shlex
import tempfile
import time
import types
import shutil
import urllib
import numbers
@ -588,7 +588,7 @@ def link_or_copy_directory(src, dst):
def module_from_path(path, name):
# Adapted from http://sayspy.blogspot.com/2011/07/how-to-import-module-from-just-file.html
mod = imp.new_module(name)
mod = types.ModuleType(name)
mod.__file__ = path
with open(path, "r") as file:
code = compile(file.read(), path, "exec", dont_inherit=True)