Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[py2py3] Fix pre-python2.6 idiom: use "isinstance()" instead of "type() == " #10172

Merged
merged 1 commit into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def execute(self, lfn, blockName, conn = None, transaction = None):

"""

if type(lfn) == list:
if isinstance(lfn, list):
binds = []
for entry in lfn:
binds.append({'block': blockName, 'filelfn': entry})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SetStatus(DBFormatter):
sql = "UPDATE dbsbuffer_file SET status = :status WHERE lfn = :lfn"

def execute(self, lfns, status, conn = None, transaction = None):
if type(lfns) != list:
if not isinstance(lfns, list):
lfns = [lfns]

bindVars = []
Expand Down
2 changes: 1 addition & 1 deletion src/python/WMCore/BossAir/MySQL/NewState.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def execute(self, states, conn = None, transaction = False):
"""

binds = []
if type(states) == str:
if isinstance(states, str):
binds = {'name': states}
for state in states:
binds.append({'name': state})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def __init__(self, datasetPathList, nodeList,
"""
Initialize PhEDEx deletion with default values
"""
if type(datasetPathList) == str:
if isinstance(datasetPathList, str):
datasetPathList = [datasetPathList]
if type(nodeList) == str:
if isinstance(nodeList, str):
nodeList = [nodeList]

self.datasetPaths = set(datasetPathList)
Expand Down
2 changes: 1 addition & 1 deletion src/python/WMCore/WMBS/MySQL/Files/DeleteCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DeleteCheck(DBFormatter):


def execute(self, file = None, fileset = None, conn = None, transaction = False):
if type(file) == list:
if isinstance(file, list):
if len(file) < 1:
return
binds = []
Expand Down
2 changes: 1 addition & 1 deletion src/python/WMCore/WMBS/MySQL/Files/DeleteParentCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DeleteParentCheck(DBFormatter):


def execute(self, file, fileset, conn = None, transaction = False):
if type(file) == list:
if isinstance(file, list):
if len(file) < 1:
# Then we have nothing
return
Expand Down
2 changes: 1 addition & 1 deletion src/python/WMCore/WMBS/MySQL/Files/GetByID.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def execute(self, file = None, conn = None, transaction = False):

#Making some modifications to allow it to load a whole list of files
#This DAO object should be called directly, not through WMBSFile
if type(file) == list:
if isinstance(file, list):
#Then we have a list of the form [fileid, fileid, etc.]
if len(file) == 0:
#Ignore empty lists
Expand Down
2 changes: 1 addition & 1 deletion src/python/WMCore/WMBS/MySQL/Files/GetChecksum.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def formatResult(self, result):
formattedResult = {}

dictVersion = DBFormatter.formatDict(self, result)
if type(dictVersion) == type([]):
if isinstance(dictVersion, list):
if len(dictVersion) == 0:
#Then it's empty
return None
Expand Down
2 changes: 1 addition & 1 deletion src/python/WMCore/WMBS/MySQL/Files/GetChildIDsByID.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def getBinds(self, ids=None):
def format(self, result):
out = set()
for r in result:
if type(1) == type(r):
if isinstance(r, int):
# deal with crappy mysql implementation
out.add(int(r))
else:
Expand Down
2 changes: 1 addition & 1 deletion src/python/WMCore/WMBS/MySQL/Files/GetParentIDsByID.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def getBinds(self, ids=None):
def format(self, result):
out = set()
for r in result:
if type(1) == type(r):
if isinstance(r, int):
# deal with crappy mysql implementation
out.add(int(r))
else:
Expand Down
2 changes: 1 addition & 1 deletion src/python/WMCore/WMBS/MySQL/Jobs/CompleteInput.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class CompleteInput(DBFormatter):
"""

def execute(self, id, lfnsToSkip = None, conn = None, transaction = False):
if type(id) == list:
if isinstance(id, list):
binds = []
for singleID in id:
binds.append({"jobid": singleID})
Expand Down
2 changes: 1 addition & 1 deletion src/python/WMCore/WMBS/MySQL/Jobs/GetCouchID.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def execute(self, jobID, conn = None, transaction = False):
Execute the SQL for the given job ID and then format and return
the result.
"""
if type(jobID) == list:
if isinstance(jobID, list):
if len(jobID) == 0:
return {}
binds = []
Expand Down
2 changes: 1 addition & 1 deletion src/python/WMCore/WMBS/MySQL/Jobs/GetLocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def execute(self, jobid, conn = None, transaction = False):
the result.
"""

if type(jobid) == list:
if isinstance(jobid, list):
result = self.dbi.processData(self.bulkSQL, jobid, conn = conn, transaction = transaction)
tmp = self.formatDict(result)
return tmp
Expand Down
2 changes: 1 addition & 1 deletion src/python/WMCore/WMBS/MySQL/Jobs/GetType.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class GetType(DBFormatter):
WHERE wmbs_job.id = :jobid"""

def execute(self, jobID, conn = None, transaction = False):
isList = type(jobID) == type([])
isList = isinstance(jobID, list)
if isList:
binds = []
for job in jobID:
Expand Down
2 changes: 1 addition & 1 deletion src/python/WMCore/WMBS/MySQL/Jobs/LoadForTaskArchiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def execute(self, jobID, conn = None, transaction = False):
the result.
"""

if type(jobID) != list:
if not isinstance(jobID, list):
jobID = [jobID]

binds = [{"jobid": x} for x in jobID]
Expand Down
2 changes: 1 addition & 1 deletion src/python/WMCore/WMBS/MySQL/Jobs/New.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def format(self, input):
def execute(self, jobgroup = None, name = None, couch_record = None, location = None, cache_dir = None,
outcome = None, fwjr = None, conn = None, transaction = False, jobList = None):

if outcome == None or type(outcome) != str:
if outcome == None or not isinstance(outcome, str):
outcome = 'failure'
elif outcome.lower() == 'success':
boolOutcome = 1
Expand Down
2 changes: 1 addition & 1 deletion src/python/WMCore/WMBS/MySQL/Jobs/SetCouchID.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def execute(self, jobID = None, couchID = None, bulkList = None, conn = None,
Update the location of the couch record for the job.
"""

if type(bulkList) == list:
if isinstance(bulkList, list):
binds = bulkList
else:
binds = {"jobid": jobID, "couchid": couchID}
Expand Down
2 changes: 1 addition & 1 deletion src/python/WMCore/WMBS/MySQL/Masks/Save.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Save(DBFormatter):
"""

def execute(self, jobid, mask, conn = None, transaction = False):
if type(mask) == list:
if isinstance(mask, list):
# Bulk commit
# Hope you didn't send us a list of empty masks
binds = []
Expand Down
2 changes: 1 addition & 1 deletion src/python/WMCore/WMBS/MySQL/Subscriptions/AcquireFiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AcquireFiles(DBFormatter):

def execute(self, subscription = None, file = None, conn = None,
transaction = False):
if type(file) == type([]):
if isinstance(file, list):
binds = []
for fileid in file:
binds.append({"subscription": subscription, "fileid": fileid})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class GetCompletedByFileList(DBFormatter):
def format(self, result):
out = []
for r in result:
if type(1) == type(r):
if isinstance(r, int):
# deal with crappy mysql implementation
out.append(int(r))
else:
Expand Down
2 changes: 1 addition & 1 deletion src/python/WMCore/WMBS/MySQL/Subscriptions/GetSubTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def formatThis(self, result):
final = []

for item in res:
if type(item) == list:
if isinstance(item, list):
final.extend(item)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def execute(self, ids, finished = True, conn = None,
finished = 0

#Make sure it's a list of IDs
if type(ids) != list:
if not isinstance(ids, list):
ids = [ids]

binds = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def execute(self, tasks, conn = None, transaction = False):
Runs the query
"""

if type(tasks) != list:
if not isinstance(tasks, list):
tasks = [tasks]

binds = []
Expand Down
7 changes: 3 additions & 4 deletions src/python/WMCore/WMRuntime/ProcessMonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def setArgs(self, arguments):
Either accepts a list of arguments which are passed to execvp
OR accepts a string which is passed to bash and shell-expanded
"""
if (type(arguments) != type.ListType):
if not isinstance(arguments, list):
# we got passed a string, pass it to a shell
self.args[0] = 'bash'
self.args[1] = '-c'
Expand All @@ -145,9 +145,8 @@ class PythonProcess(ChildProcess):
def __init__(self):
self.target = None

def setTarget(self,newtarget):
if ((type(newtarget) != FunctionType) and
(type(newtarget) != LambdaType)):
def setTarget(self, newtarget):
if not isinstance(newtarget, (FunctionType, LambdaType)):
raise RuntimeError("PythonProcess requires a function for target")

self.target = newtarget
Expand Down
14 changes: 7 additions & 7 deletions src/python/WMCore/WMSpec/ConfigSectionTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def format(value):
format a value as python
keep parameters simple, trust python...
"""
if type(value) == str:
if isinstance(value, str):
mapellidario marked this conversation as resolved.
Show resolved Hide resolved
value = "\'%s\'" % value
return str(value)

Expand All @@ -238,14 +238,14 @@ def formatNative(value):
Like the format function, but allowing passing of ints, floats, etc.
"""

if type(value) == int:
if isinstance(value, int):
return value
if type(value) == float:
if isinstance(value, float):
return value
if type(value) == list:
if isinstance(value, list):
return value
if isinstance(value, dict):
return value
if type(value) == dict:
return dict
else:
return format(value)

Expand Down Expand Up @@ -398,7 +398,7 @@ def addValue(self, value):
adds an arbitrary value as a dictionary. Can have multiple values
"""

if not type(value) == dict:
if not isinstance(value, dict):
raise Exception("TreeHelper.addValue passed a value that was not a dictionary")

for key in value:
Expand Down
2 changes: 1 addition & 1 deletion src/python/WMCore/WMSpec/Steps/BuildTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def processDir( cfgSect, parent):
"""
for setting in cfgSect._internal_settings:
value = getattr(cfgSect, setting)
if type(value) != type(dict()): continue
if not isinstance(value, dict): continue
parent.addFile(value['Source'], value['Target'])

for subdir in cfgSect._internal_children:
Expand Down
6 changes: 3 additions & 3 deletions src/python/WMCore/WebTools/WebAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def json(self, *args, **kwargs):
# dict = self.runMethod(args[0], kwargs)
# return dict
res = self.runMethod(args[0], kwargs)
if type(res) is str:
if isinstance(res, str):
mapellidario marked this conversation as resolved.
Show resolved Hide resolved
res = eval(res)
return res
else:
Expand Down Expand Up @@ -122,7 +122,7 @@ def plist(self, *args, **kwargs):
"""
try:
res = self.runMethod(args[0], kwargs)
if type(res) is str:
if isinstance(res, str):
res = eval(res)
return res
except:
Expand All @@ -138,7 +138,7 @@ def xml(self, *args, **kwargs):
# dict = self.runMethod(args[0], kwargs)
# return dict
res = self.runMethod(args[0], kwargs)
if type(res) is str:
if isinstance(res, str):
res = eval(res)
return res
else:
Expand Down