Don't let module imports have side-effects.
The pretty printer module was inscribing the trace command as a side- effect of importing it.
This commit is contained in:
parent
5a2758b50d
commit
1cf82b8bcb
|
|
@ -17,12 +17,12 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with Thun. If not see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from __future__ import print_function
|
||||
from .library import initialize
|
||||
from .library import initialize, inscribe
|
||||
from .joy import repl
|
||||
from .utils import pretty_print # Inscribe trace command.
|
||||
from .utils.pretty_print import trace
|
||||
|
||||
|
||||
inscribe(trace)
|
||||
print('''\
|
||||
Thun - Copyright © 2017 Simon Forman
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type "warranty".
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ attempts to stay very close to the spirit of Joy but does not precisely
|
|||
match the behaviour of the original version(s) written in C.
|
||||
|
||||
'''
|
||||
from __future__ import print_function
|
||||
from builtins import input
|
||||
from traceback import print_exc
|
||||
from .parser import text_to_expression, ParseError, Symbol
|
||||
|
|
|
|||
|
|
@ -38,15 +38,12 @@ the pending expression to the right.
|
|||
'''
|
||||
# (Kinda clunky and hacky. This should be swapped out in favor of much
|
||||
# smarter stuff.)
|
||||
from __future__ import print_function
|
||||
from builtins import object
|
||||
from traceback import print_exc
|
||||
from .stack import expression_to_string, stack_to_string
|
||||
from ..joy import joy
|
||||
from ..library import inscribe, FunctionWrapper
|
||||
from ..library import FunctionWrapper
|
||||
|
||||
|
||||
@inscribe
|
||||
@FunctionWrapper
|
||||
def trace(stack, expression, dictionary):
|
||||
'''Evaluate a Joy expression on a stack and print a trace.
|
||||
|
|
@ -114,10 +111,10 @@ class TracePrinter(object):
|
|||
if n > max_stack_length:
|
||||
max_stack_length = n
|
||||
lines.append((n, '%s • %s' % (stack, expression)))
|
||||
return [ # Prefix spaces to line up '•'s.
|
||||
(' ' * (max_stack_length - length) + line)
|
||||
for length, line in lines
|
||||
]
|
||||
for i in range(len(lines)): # Prefix spaces to line up '•'s.
|
||||
length, line = lines[i]
|
||||
lines[i] = (' ' * (max_stack_length - length) + line)
|
||||
return lines
|
||||
|
||||
def print_(self):
|
||||
try:
|
||||
|
|
|
|||
Loading…
Reference in New Issue