for i, line in enumerate(fastafile):
line_blen = len(line)
line_clen = len(line.rstrip('\n\r'))
lastline = i
lastline is not initialized before the for loop. So if fastafile is empty, lastline is not set. But it is then used on line 452. This results in
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/case.py", line 331, in run
testMethod()
File "/Users/terry/dark-matter/dark-matter/test/test_fasta.py", line 459, in testEmpty
reads = FastaFaiReads('filename.fasta')
File "/Users/terry/dark-matter/dark-matter/dark/fasta.py", line 146, in __init__
self._fasta = Fasta(filename)
File "build/bdist.macosx-10.10-intel/egg/pyfaidx/__init__.py", line 724, in __init__
File "build/bdist.macosx-10.10-intel/egg/pyfaidx/__init__.py", line 351, in __init__
File "build/bdist.macosx-10.10-intel/egg/pyfaidx/__init__.py", line 452, in build_index
exceptions.UnboundLocalError: local variable 'lastline' referenced before assignment
In
__init__.py
there's this code:lastline
is not initialized before thefor
loop. So iffastafile
is empty,lastline
is not set. But it is then used on line 452. This results in