[IPython-User] Advice on using a prefilter
Mon Aug 6 18:39:52 CDT 2012
I'm trying to write an input prefilter for SymPy that wraps integer
literals with Integer, so that things like 1/2 will produce
Rational(1, 2). On the advice of minrk on IRC, I'm using something
(particularly the code at the very bottom). I have some questions,
- What is the purpose of the continue_prompt argument to transform()?
- How do I make this work for multi-line inputs. So far, I have something like
In : 1/2
In : def f():
...: return 1/2
In : f()
The transformer doesn't seem to be called at all if the input is more
than one line (it doesn't seem to matter if this is because it's a
block or just because of a line continuation).
- If the input is bad, it raises a SyntaxError, but on the transformed
expresion. This is expected, but I'd like to avoid it for user
experience purposes. What is the best way to fall back to the original
input in the case of a SyntaxError?
- The code at https://bitbucket.org/birkenfeld/ipython-physics/src/71b2d850da00/physics.py
claims that the transformer object is supposed to subclass
PrefilterTransformer, but it doesn't work. I also didn't get it to
work. If I do, I get
Traceback (most recent call last):
File "./bin/isympy", line 305, in <module>
File "./bin/isympy", line 298, in main
from sympy.utilities.exceptions import SymPyDeprecationWarning
line 75, in <module>
from interactive import init_session, init_printing
line 4, in <module>
from session import init_session
line 129, in <module>
int_transformer = IntTransformer()
line 383, in __init__
AttributeError: 'NoneType' object has no attribute 'register_transformer'
Is this a bug?
If it would help, I can push up what I've done so far to GitHub.
More information about the IPython-User