Skip to content

Commit 6f5423a

Browse files
rmaxdangra
authored andcommitted
Replaced remaning __import__(module) calls.
This commit replaces the statements __import__(module) as the previous replaced the statements __import__(module, {}, {}, ['']). At first I thought leaving the single-argument calls, but perhaps it's better to be strict rather than having exceptions to the rule in this case.
1 parent 6b1760d commit 6f5423a

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

scrapy/contrib/memusage.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import socket
88
from pprint import pformat
9+
from importlib import import_module
910

1011
from twisted.internet import task
1112

@@ -20,7 +21,8 @@ def __init__(self, crawler):
2021
if not crawler.settings.getbool('MEMUSAGE_ENABLED'):
2122
raise NotConfigured
2223
try:
23-
self.resource = __import__('resource')
24+
# stdlib's resource module is only availabe on unix platforms.
25+
self.resource = import_module('resource')
2426
except ImportError:
2527
raise NotConfigured
2628

scrapy/settings/default_settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import os
1717
import sys
18+
from importlib import import_module
1819
from os.path import join, abspath, dirname
1920

2021
BOT_NAME = 'scrapybot'
@@ -229,7 +230,7 @@
229230

230231
URLLENGTH_LIMIT = 2083
231232

232-
USER_AGENT = 'Scrapy/%s (+http://scrapy.org)' % __import__('scrapy').__version__
233+
USER_AGENT = 'Scrapy/%s (+http://scrapy.org)' % import_module('scrapy').__version__
233234

234235
TELNETCONSOLE_ENABLED = 1
235236
TELNETCONSOLE_PORT = [6023, 6073]

scrapy/tests/test_dependencies.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
from importlib import import_module
12
from twisted.trial import unittest
23

34
class ScrapyUtilsTest(unittest.TestCase):
45
def test_required_openssl_version(self):
56
try:
6-
module = __import__('OpenSSL')
7+
module = import_module('OpenSSL')
78
except ImportError as ex:
89
raise unittest.SkipTest("OpenSSL is not available")
910

scrapy/utils/test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import os
66

7+
from importlib import import_module
78
from twisted.trial.unittest import SkipTest
89

910

@@ -39,7 +40,7 @@ class SettingsModuleMock(object):
3940
def get_pythonpath():
4041
"""Return a PYTHONPATH suitable to use in processes so that they find this
4142
installation of Scrapy"""
42-
scrapy_path = __import__('scrapy').__path__[0]
43+
scrapy_path = import_module('scrapy').__path__[0]
4344
return os.path.dirname(scrapy_path) + os.pathsep + os.environ.get('PYTHONPATH', '')
4445

4546
def get_testenv():

0 commit comments

Comments
 (0)