Skip to content

Commit a0d0d4f

Browse files
gz83V8 LUCI CQ
authored andcommitted
[py3.12] Optimize some py files
1. Remove the imp module and use its equivalent instead 2. Delete unused module imports Bug: chromium:1487454 Change-Id: I06fd342ba8e17f96ee2e55926cca0efded845b2a Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4983809 Reviewed-by: Michael Achenbach <[email protected]> Commit-Queue: Ho Cheung <[email protected]> Cr-Commit-Position: refs/heads/main@{#90641}
1 parent 5a9775b commit a0d0d4f

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

test/test262/testcfg.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,13 @@
2525
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2626
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2727

28-
import imp
29-
import itertools
30-
import os
31-
import re
28+
import importlib.machinery
3229
import sys
3330

3431
from pathlib import Path
3532

3633
from testrunner.local import statusfile
3734
from testrunner.local import testsuite
38-
from testrunner.local import utils
3935
from testrunner.objects import testcase
4036
from testrunner.outproc import base as outproc
4137
from testrunner.outproc import test262
@@ -146,11 +142,12 @@ def _load_parse_test_record(self):
146142
root = TEST_262_TOOLS_ABS_PATH
147143
f = None
148144
try:
149-
(f, pathname, description) = imp.find_module("parseTestRecord", [root])
150-
module = imp.load_module("parseTestRecord", f, pathname, description)
145+
loader = importlib.machinery.SourceFileLoader(
146+
"parseTestRecord", f"{root}/parseTestRecord.py")
147+
module = loader.load_module()
151148
return module.parseTestRecord
152-
except:
153-
print('Cannot load parseTestRecord')
149+
except Exception as e:
150+
print(f'Cannot load parseTestRecord: {e}')
154151
raise
155152
finally:
156153
if f:

tools/testrunner/local/testsuite.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@
2626
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2727

2828

29-
import imp
29+
import importlib.machinery
3030
import itertools
3131
import os
3232

3333
from contextlib import contextmanager
3434
from pathlib import Path
3535

3636
from . import statusfile
37-
from . import utils
3837
from .variants import ALL_VARIANTS, ALL_VARIANT_FLAGS
3938

4039

@@ -232,12 +231,13 @@ def merge(self, test_generator):
232231
def _load_testsuite_module(name, root):
233232
f = None
234233
try:
235-
(f, pathname, description) = imp.find_module("testcfg", [root])
236-
yield imp.load_module(name + "_testcfg", f, pathname, description)
234+
yield importlib.machinery.SourceFileLoader(
235+
name + "_testcfg", f"{root}/testcfg.py").load_module()
237236
finally:
238237
if f:
239238
f.close()
240239

240+
241241
class TestSuite(object):
242242
@staticmethod
243243
def Load(ctx, root, test_config):

0 commit comments

Comments
 (0)