Permalink
Browse files

Fix PEP8 warnings/errors E712, W601 and W602.

E712 comparison to False should be 'if cond is False:' or 'if not cond:'
W601 .has_key() is deprecated, use 'in'
W602 deprecated form of raising exception
  • Loading branch information...
1 parent 4576bea commit e19c029ef7a194c7b63716f2546b35e47a3d3f36 @cbrueffer cbrueffer committed Dec 3, 2012
@@ -69,7 +69,7 @@ def feed(self, data, isFinal = 0):
# fed to the parser.
if self.firsttime:
if data[:5]!="<?xml":
- raise ValueError, data
+ raise ValueError(data)
self.firsttime = False
return ExpatParser.feed(self, data, isFinal)
@@ -231,7 +231,7 @@ def __init__(self, parent=None, pagesize='A3', orientation='landscape',
# Useful measurements on the page
self.track_size = track_size
self.circle_core = circle_core
- if circular == False: # Determine the proportion of the circumference
+ if not circular: # Determine the proportion of the circumference
self.sweep = 0.9 # around which information will be drawn
else:
self.sweep = 1
@@ -79,7 +79,7 @@ def translate(self, color=None, colour=None):
color = colour
if color is None:
- raise ValueError, "Passed color (or colour) must be a valid color type"
+ raise ValueError("Passed color (or colour) must be a valid color type")
elif isinstance(color, int):
color = self.scheme_color(color)
elif isinstance(color, colors.Color):
View
@@ -60,7 +60,7 @@ def __init__(self, indexname, truncate=None):
% (version, self.__version))
def __del__(self):
- if self.__dict__.has_key('data'):
+ if 'data' in self.__dict__:
self.data.close()
class _InMemoryIndex(dict):
View
@@ -554,7 +554,7 @@ def _from_vert_matrix(self,stream,letters=None,make_instances=False):
self.counts[k].append(v)
self.length+=1
self.set_mask("*"*self.length)
- if make_instances==True:
+ if make_instances is True:
self.make_instances_from_counts()
return self
@@ -582,7 +582,7 @@ def _from_horiz_matrix(self,stream,letters=None,make_instances=False):
l = len(self.counts[letters[0]])
self.length=l
self.set_mask("*"*l)
- if make_instances==True:
+ if make_instances is True:
self.make_instances_from_counts()
return self
View
@@ -150,7 +150,7 @@ def make_dssp_dict(filename):
phi = float(l[103+shift:109+shift])
psi = float(l[109+shift:115+shift])
else:
- raise ValueError, exc
+ raise ValueError(exc)
res_id = (" ", resseq, icode)
dssp[(chainid, res_id)] = (aa, ss, acc, phi, psi)
keys.append((chainid, res_id))
@@ -73,14 +73,14 @@ def set_options(self, **kwargs):
adding options that do not exist or mispelling options.
"""
for option, value in kwargs.items():
- if not self._options.has_key(option):
+ if not option in self._options:
raise KeyError("Invalid option: " + option)
else:
self._options[option] = value
def get_option(self, option):
"""Return the value of an option."""
- if not self._options.has_key(option):
+ if not option in self._options:
raise KeyError("Invalid option: " + option)
else:
return self._options.get(option)
@@ -96,7 +96,7 @@ def init_pop():
if report_pops:
report_pops(num_pops)
while lParser:
- if lParser != True:
+ if lParser is not True:
for loci_pos in range(num_loci):
for al in lParser[1][loci_pos]:
if al is not None:
@@ -160,7 +160,7 @@ def countPops(rec):
pop_data = []
lParser = work_rec.get_individual()
while lParser:
- if lParser != True:
+ if lParser is not True:
for al in lParser[1][lc_i]:
if al is not None and al not in alleles:
alleles.append(al)
@@ -178,7 +178,7 @@ def process_pop(pop_data, alleles, allele_counts):
allele_counts[allele] = 0
allele_counts[None]=0
while lParser:
- if lParser == True:
+ if lParser is True:
process_pop(pop_data, alleles, allele_counts)
allele_counts = {}
for allele in alleles:
@@ -242,7 +242,7 @@ def _get_opts(self, dememorization, batches, iterations, enum_test=None):
opts["BatchNumber"]=batches
opts["BatchLength"]=iterations
if enum_test != None:
- if enum_test == True:
+ if enum_test is True:
opts["HWtests"]="Enumeration"
else:
opts["HWtests"]="MCMC"
@@ -84,9 +84,9 @@ def __str__(self):
more = True
while more:
res = self.get_individual()
- if res == True:
+ if res is True:
rep.append('Pop\n')
- elif res == False:
+ elif res is False:
more = False
else:
name, markers = res
@@ -203,7 +203,7 @@ def remove_population(self, pos, fname):
old_rec.skip_population()
curr_pop += 1
else:
- if l_parser == True:
+ if l_parser is True:
curr_pop += 1
start_pop = True
else:
@@ -242,7 +242,7 @@ def remove_locus_by_position(self, pos, fname):
l_parser = old_rec.get_individual()
f.write("POP\n")
while l_parser:
- if l_parser == True:
+ if l_parser is True:
f.write("POP\n")
else:
name, markers = l_parser
@@ -287,7 +287,7 @@ def remove_loci_by_position(self, positions, fname):
l_parser = old_rec.get_individual()
f.write("POP\n")
while l_parser:
- if l_parser == True:
+ if l_parser is True:
f.write("POP\n")
else:
name, markers = l_parser
@@ -51,10 +51,10 @@ def UniprotIterator(handle, alphabet=Alphabet.ProteinAlphabet(), return_raw_comm
skip_parsing_errors = True --> if parsing errors are found, skip to next entry
"""
if isinstance(alphabet, Alphabet.NucleotideAlphabet):
- raise ValueError, "Wrong alphabet %r" % alphabet
+ raise ValueError("Wrong alphabet %r" % alphabet)
if isinstance(alphabet, Alphabet.Gapped):
if isinstance(alphabet.alphabet, Alphabet.NucleotideAlphabet):
- raise ValueError, "Wrong alphabet %r" % alphabet
+ raise ValueError("Wrong alphabet %r" % alphabet)
if not hasattr(handle, "read"):
if type(handle) == type(''):
View
@@ -26,7 +26,7 @@ def match(string, trie):
substr = string[:i+1]
if not trie.has_prefix(substr):
break
- if trie.has_key(substr):
+ if substr in trie:
longest = substr
return longest
@@ -42,7 +42,7 @@ def match_all(string, trie):
substr = string[:i+1]
if not trie.has_prefix(substr):
break
- if trie.has_key(substr):
+ if substr in trie:
matches.append(substr)
return matches
@@ -97,9 +97,9 @@ def test_file_record_parser(self):
assert isinstance(rec, FileParser.FileRecord)
assert len(rec.loci_list) == self.num_loci[index]
for skip in range(self.pops_indivs[index][0]):
- if rec.skip_population() == False:
+ if rec.skip_population() is False:
raise Error("Not enough populations")
- if rec.skip_population() == True:
+ if rec.skip_population() is True:
raise Error("Too much populations")
for i in range(self.pops_indivs[index][0]):
continue
View
@@ -48,9 +48,9 @@ def test_prefix(self):
self.assertEqual(k, ["foo", "he", "hej", "hello"])
self.assertEqual(trieobj["hello"], 5)
self.assertEqual(trieobj.get("bye"), None)
- self.assertEqual(trieobj.has_key("hello"), True)
- self.assertEqual(trieobj.has_key("he"), True)
- self.assertEqual(trieobj.has_key("bye"), False)
+ self.assertTrue("hello" in trieobj)
+ self.assertTrue("he" in trieobj)
+ self.assertFalse("bye" in trieobj)
self.assertEqual(trieobj.has_prefix("h"), True)
self.assertEqual(trieobj.has_prefix("hel"), True)
self.assertEqual(trieobj.has_prefix("foa"), False)

2 comments on commit e19c029

@peterjc
Member
peterjc commented on e19c029 Dec 3, 2012

Note the trie changes broke the unit tests, for example https://travis-ci.org/biopython/biopython/builds/3477275

The trie object is written in C and doesn't (yet) support 'in', so we still have to use has_key for now, reverted here:
0606a23

@cbrueffer
Member

Hi Peter, I have submitted a fix in #104 a minute ago (thanks to bow). Sorry for the breakage!

Please sign in to comment.