Skip to content

Commit 10f1592

Browse files
author
Thomas Preud'homme
committed
[LNT][NFC] Fix global import in function
Summary: The _load_dependencies() function in lnt.lnttool.admin import some modules in the global namespace by making the module name global and then doing imports. However the language reference for global statements forbids this: "Names listed in a global statement must not be defined as formal parameters or in a for loop control target, class definition, function definition, or import statement." This commit makes use of importlib.import_module wrapper instead of the import statement to respect this restriction. Reviewers: cmatthews, hubert.reinterpretcast, kristof.beyls, PrzemekWirkus Reviewed By: PrzemekWirkus Subscribers: PrzemekWirkus, leandron, MatzeB, llvm-commits Differential Revision: https://reviews.llvm.org/D68779
1 parent 72b3374 commit 10f1592

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lnt/lnttool/admin.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
from future import standard_library
33
standard_library.install_aliases()
44
import click
5+
from importlib import import_module
56
from .common import submit_options
67

78

89
def _load_dependencies():
910
global yaml, sys, requests, json, os, http
10-
import yaml
11-
import sys
12-
import requests
13-
import json
14-
import os
15-
import http.client
11+
yaml = import_module('yaml')
12+
sys = import_module('sys')
13+
requests = import_module('requests')
14+
json = import_module('json')
15+
os = import_module('os')
16+
http = import_module('http.client')
1617

1718

1819
def _error(msg):

0 commit comments

Comments
 (0)