Skip to content

Commit 9d1f66f

Browse files
reginalinikonst
authored andcommitted
use importlib instead of deprecated imp (#723)
On Python>=3.3.
1 parent 5a9a98a commit 9d1f66f

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

pynamodb/_compat.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
import six
2+
import sys
23

34
if six.PY2:
45
from inspect import getargspec as getfullargspec
56
else:
67
from inspect import getfullargspec
78

8-
__all__ = ('getfullargspec',)
9+
def load_module(name, path):
10+
"""Load module using the Python version compatible function."""
11+
if sys.version_info >= (3, 3):
12+
from imp import load_source
13+
from importlib.machinery import SourceFileLoader
14+
return SourceFileLoader(name, path).load_module()
15+
else:
16+
from imp import load_source
17+
return load_source(name, path)
18+
19+
__all__ = ('getfullargspec', 'load_module')

pynamodb/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import imp
21
import logging
32
import os
43
import warnings
54
from os import getenv
5+
from pynamodb._compat import load_module
66

77
log = logging.getLogger(__name__)
88

@@ -20,7 +20,7 @@
2020

2121
override_settings = {}
2222
if os.path.isfile(OVERRIDE_SETTINGS_PATH):
23-
override_settings = imp.load_source('__pynamodb_override_settings__', OVERRIDE_SETTINGS_PATH)
23+
override_settings = load_module('__pynamodb_override_settings__', OVERRIDE_SETTINGS_PATH)
2424
if hasattr(override_settings, 'session_cls') or hasattr(override_settings, 'request_timeout_seconds'):
2525
warnings.warn("The `session_cls` and `request_timeout_second` options are no longer supported")
2626
log.info('Override settings for pynamo available {}'.format(OVERRIDE_SETTINGS_PATH))

0 commit comments

Comments
 (0)