You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
better exception handling for syntax exception in python blocks #245
Migrated issue, originally created by jvanasco (@jvanasco)
Here's a trivial/dumb example
<%def name="foo(\
bar,
biz = False,
bash = False,
bang = None,
)">
<%
# ok sample
# more sample
if True:
fizz = 'bang'
if biz is not True:
biz = 'fizz'
%>
${biz}
</%def>
Imagine, if you can, that the if biz is not True: is malformed, because of a sticky key -- an "option+Space" combination creates a non-printing character that looks like a space in most editors, but is really bastardized character \xc2.
If normal Python encounters that, we get this error:
SyntaxException: (SyntaxError) invalid syntax (<unknown>, line 7) (u'# ok sample') in file '/....mako' at line: 477 char: 1
The mako exception will always point to the first line of the function (after declaration), not the actual line. It also doesn't show the underlying syntax error. I'm not sure where that got lost.
Activity
sqlalchemy-bot commentedon Jul 6, 2015
Michael Bayer (@zzzeek) wrote:
not sure how to fix
sqlalchemy-bot commentedon Jul 6, 2015
Changes by Michael Bayer (@zzzeek):
sqlalchemy-bot commentedon Jul 6, 2015
jvanasco (@jvanasco) wrote:
Yeah I was lost on this. I had a bad version of my pep8 ticket working locally (which is how I found my big), but couldn't figure this one out.
sqla-tester commentedon Aug 4, 2026
Mike Bayer has proposed a fix for this issue in the main branch:
Report the line of a syntax error within a python block https://gerrit.sqlalchemy.org/c/sqlalchemy/mako/+/6865
Report the line of a syntax error within a python block