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
1=== modified file 'storm/expr.py'
2--- storm/expr.py 2009-06-18 15:05:18 +0000
3+++ storm/expr.py 2009-07-10 05:20:10 +0000
4@@ -473,6 +473,9 @@
5 other = getattr(self, "variable_factory", Variable)(value=other)
6 return Mod(self, other)
7
8+ def __neg__(self):
9+ return Neg(self)
10+
11 def is_in(self, others):
12 if not isinstance(others, Expr):
13 others = list(others)
14@@ -1270,6 +1273,14 @@
15 __slots__ = ()
16 prefix = "EXISTS"
17
18+class Neg(PrefixExpr):
19+ __slots__ = ()
20+ prefix = "-"
21+
22+@compile_python.when(Neg)
23+def compile_neg_expr(compile, expr, state):
24+ return "-%s" % compile(expr.expr, state, raw=True)
25+
26 class Asc(SuffixExpr):
27 __slots__ = ()
28 suffix = "ASC"
29
30=== modified file 'tests/expr.py'
31--- tests/expr.py 2009-06-18 15:05:18 +0000
32+++ tests/expr.py 2009-07-10 05:20:10 +0000
33@@ -1330,6 +1330,19 @@
34 self.assertEquals(statement, "EXISTS func1()")
35 self.assertEquals(state.parameters, [])
36
37+ def test_neg(self):
38+ expr = Neg(Func1())
39+ state = State()
40+ statement = compile(expr, state)
41+ self.assertEquals(statement, "- func1()")
42+ self.assertEquals(state.parameters, [])
43+
44+ expr = -Func1()
45+ state = State()
46+ statement = compile(expr, state)
47+ self.assertEquals(statement, "- func1()")
48+ self.assertEquals(state.parameters, [])
49+
50 def test_asc(self):
51 expr = Asc(Func1())
52 state = State()
53@@ -2107,6 +2120,11 @@
54 py_expr = compile_python(expr)
55 self.assertEquals(py_expr, "elem1+elem2+elem3+elem4")
56
57+ def test_neg(self):
58+ expr = Neg(elem1)
59+ py_expr = compile_python(expr)
60+ self.assertEquals(py_expr, "-elem1")
61+
62 def test_sub(self):
63 expr = Sub(elem1, Sub(elem2, elem3))
64 py_expr = compile_python(expr)

Subscribers

People subscribed via source and target branches

to status/vote changes: