Skip to content
Permalink
Browse files

python3: dict.has_key("key") --> "key" in dict

  • Loading branch information...
looooo authored and yorikvanhavre committed Jan 19, 2017
1 parent 7c15e14 commit e9b5722220d43fb3dce1d887594e038803d5bbab
@@ -356,7 +356,7 @@ def closeHole(shape):
for face in shape.Faces:
for edge in face.Edges:
hc = edge.hashCode()
if lut.has_key(hc):
if hc in lut:
lut[hc] = lut[hc] + 1
else:
lut[hc] = 1
@@ -281,7 +281,7 @@ def process_emp(doc,filename,placement,board_thickness):
comps=dict(comps)
grp=doc.addObject("App::DocumentObjectGroup", "EMP Models")
for place_item in placement:
if comps.has_key(place_item[1]):
if place_item[1] in comps:
doc_comp=doc.addObject("Part::Feature",place_item[0])
FreeCAD.Console.PrintMessage("Adding EMP model "+str(place_item[0])+"\n")
doc_comp.Shape=comps[place_item[1]][0]
@@ -362,7 +362,7 @@ def place_steps(doc,placement,board_thickness):
step_dict=dict(step_dict)
grp=doc.addObject("App::DocumentObjectGroup", "Step Models")
for place_item in placement:
if step_dict.has_key(place_item[2]):
if place_item[2] in step_dict:
step_model=doc.addObject("Part::Feature",place_item[0]+"_s")
FreeCAD.Console.PrintMessage("Adding STEP model "+str(place_item[0])+"\n")
#if prev_step!=place_item[2]:
@@ -46,7 +46,7 @@ def get_type(self):
if type(self._typedef) == str:
if self._scope == None:
raise AssertionError('No scope defined for this type')
elif vars(self._scope).has_key(self._typedef):
elif self._typedef in vars(self._scope):
return vars(self._scope)[self._typedef]
else:
raise TypeError("Type '%s' is not defined in given scope"%self._typedef)
@@ -70,7 +70,7 @@ class ENUMERATION(object):
"""
def __init__(self,*kargs,**args):
# first defining the scope
if args.has_key('scope'):
if 'scope' in args:
self._scope = args['scope']
else:
self._scope = None
@@ -96,7 +96,7 @@ def __init__(self,*kargs,**args):
# has the same name as an enum id, it will replace it in the current scope.
#
for enum_id_name in self._enum_id_names:
if not vars(self._scope).has_key(enum_id_name):
if enum_id_name not in vars(self._scope):
vars(self._scope)[enum_id_name] = self.__getattribute__(enum_id_name)

def get_enum_ids(self):
@@ -109,7 +109,7 @@ class SELECT(object):
"""
def __init__(self,*kargs,**args):
# first defining the scope
if args.has_key('scope'):
if 'scope' in args:
self._scope = args['scope']
else:
self._scope = None
@@ -107,11 +107,11 @@ def instaciate(self):

for i in self._p21loader._instances_definition.keys():
#print i
if not self.instanceMape.has_key(i):
if i not in self.instanceMape:
self._create_entity_instance(i)

def _create_entity_instance(self, instance_id):
if self._p21loader._instances_definition.has_key(instance_id):
if instance_id in self._p21loader._instances_definition:
instance_definition = self._p21loader._instances_definition[instance_id]
#print "Instance definition to process",instance_definition
# first find class name
@@ -144,11 +144,11 @@ def _transformAttributes(self,attrList):
elif i[0] == '#':
key = int(i[1:])
#print 'Item: ',int(i[1:])
if self.instanceMape.has_key(key):
if key in self.instanceMape:
attrList[n] = self.instanceMape[key]
else:
self._create_entity_instance(key)
if not self.instanceMape.has_key(key):
if key not in self.instanceMape:
raise NameError("Needed instance not instanciated: ",key)
else:
attrList[n] = self.instanceMape[key]
@@ -76,7 +76,7 @@ def modifyVPProperty(self, doc_obj_or_list, prop_name, new_value):
oldval = getattr(doc_obj.ViewObject, prop_name)
setattr(doc_obj.ViewObject, prop_name, new_value)
self.restore_on_delete = True
if not self.data.has_key((doc_obj.Name,prop_name)):
if (doc_obj.Name,prop_name) not in self.data:
self.data[(doc_obj.Name,prop_name)] = oldval

def show(self, doc_obj_or_list):
@@ -225,7 +225,7 @@ def setUnpickable(self, doc_obj_or_list, actual_pick_style = 2): #2 is coin.SoPi
if actual_pick_style != oldval:
self._setPickStyle(doc_obj.ViewObject, actual_pick_style)
self.restore_on_delete = True
if not self.data_pickstyle.has_key(doc_obj.Name):
if doc_obj.Name not in self.data_pickstyle:
self.data_pickstyle[doc_obj.Name] = oldval

def restoreUnpickable(self):
@@ -162,7 +162,7 @@ def __init__(self):

def rollbackImports(self):
for modname in sys.modules.keys():
if not self.previousModules.has_key(modname):
if modname not in self.previousModules:
# Force reload when modname next imported
del(sys.modules[modname])

@@ -155,7 +155,7 @@ def __init__(self):

def rollbackImports(self):
for modname in sys.modules.keys():
if not self.previousModules.has_key(modname):
if modname not in self.previousModules:
# Force reload when modname next imported
del(sys.modules[modname])

@@ -55,7 +55,7 @@ def add_node(self, node):
self.graph[node.name] = node

def get_node(self, name):
if self.graph.has_key(name):
if name in self.graph:
return self.graph[name]
return None

@@ -212,7 +212,7 @@ def getMaxOccurs(self): return self.maxOccurs
def getRawType(self): return self.type
def getType(self):
returnType = self.type
if ElementDict.has_key(self.type):
if self.type in ElementDict:
typeObj = ElementDict[self.type]
typeObjType = typeObj.getRawType()
if typeObjType in StringType or \
@@ -427,7 +427,7 @@ def annotate_tree(self):
# attributeGroup dictionary.
def replace_attributeGroup_names(self):
for groupName in self.attributeGroupNameList:
if AttributeGroups.has_key(groupName):
if groupName in AttributeGroups:
attrGroup = AttributeGroups[groupName]
for name in attrGroup.getKeys():
attr = attrGroup.get(name)
@@ -505,7 +505,7 @@ def getName(self): return self.name
def setGroup(self, group): self.group = group
def getGroup(self): return self.group
def get(self, name, default=None):
if self.group.has_key(name):
if name in self.group:
return self.group[name]
else:
return default
@@ -514,7 +514,8 @@ def getKeys(self):
def add(self, name, attr):
self.group[name] = attr
def delete(self, name):
if has_key(self.group, name):
# if has_key(self.group, name):
if name in self.group:
del self.group[name]
return 1
else:

0 comments on commit e9b5722

Please sign in to comment.
You can’t perform that action at this time.