Permalink
Browse files

implemented exception expressions: PEP 463

  • Loading branch information...
hartsantler committed Jul 23, 2014
1 parent 86da02e commit 3f087983b4d0ea8048f7bc72355f2b9c0a81b159
Showing with 15 additions and 0 deletions.
  1. +7 −0 README.md
  2. +8 −0 pythonjs/typedpython.py
View
@@ -127,6 +127,13 @@ a = {
}
```
+. exception expressions (PEP 463)
+```
+a = {}
+b = a['somekey'] except KeyError: 'my-default'
+```
+
+
Speed
---------------
PythonJS gives you the option to optimize your program for speed with a new syntax for static typing, in some cases this results in code that is 20X faster.
View
@@ -68,6 +68,13 @@ def transform_source( source, strip=False ):
output.append( '@func_expression(%s)' %a.strip())
c = 'def __NAMELESS__(' + b
+ if ' except ' in c: ## PEP 463 - exception expressions
+ s = c.split(' except ')
+ if len(s) == 2 and '=' in s[0]:
+ output.append('try: %s' %s[0])
+ exception, default = s[1].split(':')
+ output.append('except %s: %s=%s' %( exception, s[0].split('=')[0], default) )
+ c = ''
if '=\t\t\t\tdef ' in c:
x, c = c.split('=\t\t\t\tdef ')
@@ -241,6 +248,7 @@ def xxx():
c = function(x,y):
return x+y
+d = a[ 'somekey' ] except KeyError: 'mydefault'
'''

0 comments on commit 3f08798

Please sign in to comment.