Skip to content

Commit 5015227

Browse files
author
hartsantler
committed
Exception Expressions: fixed indented blocks.
1 parent 3f08798 commit 5015227

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

pythonjs/typedpython.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,17 @@ def transform_source( source, strip=False ):
7171
if ' except ' in c: ## PEP 463 - exception expressions
7272
s = c.split(' except ')
7373
if len(s) == 2 and '=' in s[0]:
74-
output.append('try: %s' %s[0])
74+
indent = []
75+
for char in s[0]:
76+
if char in __whitespace:
77+
indent.append( char )
78+
else:
79+
break
80+
indent = ''.join(indent)
81+
s0 = s[0].strip()
82+
output.append('%stry: %s' %(indent, s0) )
7583
exception, default = s[1].split(':')
76-
output.append('except %s: %s=%s' %( exception, s[0].split('=')[0], default) )
84+
output.append('%sexcept %s: %s=%s' %(indent, exception, s0.split('=')[0], default) )
7785
c = ''
7886

7987
if '=\t\t\t\tdef ' in c:
@@ -247,8 +255,8 @@ def xxx():
247255
248256
c = function(x,y):
249257
return x+y
250-
251-
d = a[ 'somekey' ] except KeyError: 'mydefault'
258+
if True:
259+
d = a[ 'somekey' ] except KeyError: 'mydefault'
252260
253261
'''
254262

0 commit comments

Comments
 (0)