Skip to content

Commit 13ee22f

Browse files
Merge pull request #1075 from larsoner/tb
BUG: Dont hold the exception
2 parents 3940b2d + c21f9cc commit 13ee22f

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

neo/io/stimfitio.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,6 @@
3232
from neo.io.baseio import BaseIO
3333
from neo.core import Block, Segment, AnalogSignal
3434

35-
try:
36-
import stfio
37-
except ImportError as err:
38-
HAS_STFIO = False
39-
STFIO_ERR = err
40-
else:
41-
HAS_STFIO = True
42-
STFIO_ERR = None
43-
4435

4536
class StimfitIO(BaseIO):
4637
"""
@@ -99,8 +90,9 @@ def __init__(self, filename=None):
9990
Arguments:
10091
filename : Either a filename or a stfio Recording object
10192
"""
102-
if not HAS_STFIO:
103-
raise STFIO_ERR
93+
# We need this module, so try importing now so that it fails on
94+
# instantiation rather than read_block
95+
import stfio # noqa
10496

10597
BaseIO.__init__(self)
10698

@@ -112,6 +104,7 @@ def __init__(self, filename=None):
112104
self.filename = None
113105

114106
def read_block(self, lazy=False):
107+
import stfio
115108
assert not lazy, 'Do not support lazy'
116109

117110
if self.filename is not None:

neo/test/iotest/test_stimfitio.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@
88
import unittest
99

1010
from neo.io import StimfitIO
11-
from neo.io.stimfitio import HAS_STFIO
1211
from neo.test.iotest.common_io_test import BaseTestIO
1312

13+
try:
14+
import stfio
15+
except Exception:
16+
HAS_STFIO = False
17+
else:
18+
HAS_STFIO = True
19+
1420

1521
@unittest.skipIf(sys.version_info[0] > 2, "not Python 3 compatible")
1622
@unittest.skipUnless(HAS_STFIO, "requires stfio")

0 commit comments

Comments
 (0)