Skip to content

Commit 6367a85

Browse files
author
Marien Zwart
committed
Make bpython.urwid work better without Twisted installed.
1 parent b2e0c4a commit 6367a85

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

bpython/urwid.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ def buildProtocol(self, addr):
113113
return EvalProtocol(self.repl)
114114

115115

116-
if urwid.VERSION < (1, 0, 0):
116+
# If Twisted is not available urwid has no TwistedEventLoop attribute.
117+
# Code below will try to import reactor before using TwistedEventLoop.
118+
# I assume TwistedEventLoop will be available if that import succeeds.
119+
if urwid.VERSION < (1, 0, 0) and hasattr(urwid, 'TwistedEventLoop'):
117120
class TwistedEventLoop(urwid.TwistedEventLoop):
118121

119122
"""TwistedEventLoop modified to properly stop the reactor.
@@ -144,7 +147,7 @@ def wrapper(*args, **kwargs):
144147
self.reactor.crash()
145148
return wrapper
146149
else:
147-
TwistedEventLoop = urwid.TwistedEventLoop
150+
TwistedEventLoop = getattr(urwid, 'TwistedEventLoop', None)
148151

149152

150153
class StatusbarEdit(urwid.Edit):

0 commit comments

Comments
 (0)