Merge lp:~mwhudson/storm/unary-minus into lp:storm

Proposed by Michael Hudson-Doyle
Status: Merged
Merged at revision: not available
Proposed branch: lp:~mwhudson/storm/unary-minus
Merge into: lp:storm
Diff against target: 64 lines
To merge this branch: bzr merge lp:~mwhudson/storm/unary-minus
Reviewer Review Type Date Requested Status
Gustavo Niemeyer Approve
James Henstridge Approve
Review via email: mp+8513@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Hi there.

This simple branch lets you write -Table.column expressions naturally.

It's my first storm branch, so apologies if I'm doing something wrong...

Cheers,
mwh

Revision history for this message
James Henstridge (jamesh) wrote :

> Hi there.
>
> This simple branch lets you write -Table.column expressions naturally.
>
> It's my first storm branch, so apologies if I'm doing something wrong...

This looks pretty good. Could you please add a @compile_python.when(Neg) implementation too? That should be pretty simple, and will allow ResultSet.set() to handle those expressions without invalidating all the cached objects of that type.

review: Needs Fixing
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

> > Hi there.
> >
> > This simple branch lets you write -Table.column expressions naturally.
> >
> > It's my first storm branch, so apologies if I'm doing something wrong...
>
> This looks pretty good. Could you please add a @compile_python.when(Neg)
> implementation too? That should be pretty simple, and will allow
> ResultSet.set() to handle those expressions without invalidating all the
> cached objects of that type.

Like this?

=== modified file 'storm/expr.py'
--- storm/expr.py 2009-07-10 00:35:14 +0000
+++ storm/expr.py 2009-07-10 05:08:49 +0000
@@ -1277,6 +1277,10 @@
     __slots__ = ()
     prefix = "-"

+@compile_python.when(Neg)
+def compile_neg_expr(compile, expr, state):
+ return "-%s" % compile(expr.expr, state, raw=True)
+
 class Asc(SuffixExpr):
     __slots__ = ()
     suffix = "ASC"

=== modified file 'tests/expr.py'
--- tests/expr.py 2009-07-10 00:35:14 +0000
+++ tests/expr.py 2009-07-10 05:08:49 +0000
@@ -2120,6 +2120,11 @@
         py_expr = compile_python(expr)
         self.assertEquals(py_expr, "elem1+elem2+elem3+elem4")

+ def test_neg(self):
+ expr = Neg(elem1)
+ py_expr = compile_python(expr)
+ self.assertEquals(py_expr, "-elem1")
+
     def test_sub(self):
         expr = Sub(elem1, Sub(elem2, elem3))
         py_expr = compile_python(expr)

lp:~mwhudson/storm/unary-minus updated
314. By Michael Hudson-Doyle

add compile_python.when(Neg)

Revision history for this message
James Henstridge (jamesh) wrote :

> Like this?

Yep. Looks good.

review: Approve
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Is there anything more I can do to get this moving along?

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

Looks good! +1!

This has two reviews now, so it should be good for merging.

Do you have commit access to the project Michael? If not, would you like to become a committer?

review: Approve
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

> Looks good! +1!
>
> This has two reviews now, so it should be good for merging.

Yay.

> Do you have commit access to the project Michael?

No.

> If not, would you like to become a committer?

I can't promise to spend much time on Storm tbh, but I don't mind... I'm certainly happy for someone else to merge this change.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'storm/expr.py'
--- storm/expr.py 2009-06-18 15:05:18 +0000
+++ storm/expr.py 2009-07-10 05:20:10 +0000
@@ -473,6 +473,9 @@
473 other = getattr(self, "variable_factory", Variable)(value=other)473 other = getattr(self, "variable_factory", Variable)(value=other)
474 return Mod(self, other)474 return Mod(self, other)
475475
476 def __neg__(self):
477 return Neg(self)
478
476 def is_in(self, others):479 def is_in(self, others):
477 if not isinstance(others, Expr):480 if not isinstance(others, Expr):
478 others = list(others)481 others = list(others)
@@ -1270,6 +1273,14 @@
1270 __slots__ = ()1273 __slots__ = ()
1271 prefix = "EXISTS"1274 prefix = "EXISTS"
12721275
1276class Neg(PrefixExpr):
1277 __slots__ = ()
1278 prefix = "-"
1279
1280@compile_python.when(Neg)
1281def compile_neg_expr(compile, expr, state):
1282 return "-%s" % compile(expr.expr, state, raw=True)
1283
1273class Asc(SuffixExpr):1284class Asc(SuffixExpr):
1274 __slots__ = ()1285 __slots__ = ()
1275 suffix = "ASC"1286 suffix = "ASC"
12761287
=== modified file 'tests/expr.py'
--- tests/expr.py 2009-06-18 15:05:18 +0000
+++ tests/expr.py 2009-07-10 05:20:10 +0000
@@ -1330,6 +1330,19 @@
1330 self.assertEquals(statement, "EXISTS func1()")1330 self.assertEquals(statement, "EXISTS func1()")
1331 self.assertEquals(state.parameters, [])1331 self.assertEquals(state.parameters, [])
13321332
1333 def test_neg(self):
1334 expr = Neg(Func1())
1335 state = State()
1336 statement = compile(expr, state)
1337 self.assertEquals(statement, "- func1()")
1338 self.assertEquals(state.parameters, [])
1339
1340 expr = -Func1()
1341 state = State()
1342 statement = compile(expr, state)
1343 self.assertEquals(statement, "- func1()")
1344 self.assertEquals(state.parameters, [])
1345
1333 def test_asc(self):1346 def test_asc(self):
1334 expr = Asc(Func1())1347 expr = Asc(Func1())
1335 state = State()1348 state = State()
@@ -2107,6 +2120,11 @@
2107 py_expr = compile_python(expr)2120 py_expr = compile_python(expr)
2108 self.assertEquals(py_expr, "elem1+elem2+elem3+elem4")2121 self.assertEquals(py_expr, "elem1+elem2+elem3+elem4")
21092122
2123 def test_neg(self):
2124 expr = Neg(elem1)
2125 py_expr = compile_python(expr)
2126 self.assertEquals(py_expr, "-elem1")
2127
2110 def test_sub(self):2128 def test_sub(self):
2111 expr = Sub(elem1, Sub(elem2, elem3))2129 expr = Sub(elem1, Sub(elem2, elem3))
2112 py_expr = compile_python(expr)2130 py_expr = compile_python(expr)

Subscribers

People subscribed via source and target branches

to status/vote changes: