Merge lp:~cjwatson/storm/py3-special-methods into lp:storm

Proposed by Colin Watson
Status: Merged
Merged at revision: 511
Proposed branch: lp:~cjwatson/storm/py3-special-methods
Merge into: lp:storm
Diff against target: 46 lines (+8/-0)
3 files modified
storm/expr.py (+4/-0)
storm/info.py (+2/-0)
storm/references.py (+2/-0)
To merge this branch: bzr merge lp:~cjwatson/storm/py3-special-methods
Reviewer Review Type Date Requested Status
Colin Watson Approve
Review via email: mp+371166@code.launchpad.net

Commit message

Provide needed methods for python3.

Description of the change

When a class defined __eq__ it needs to define __hash__ to or else it will not be hashable.

Also, __div__ doesn't exist anymore in python3. Classes are supposed to implement both __floordiv__ and __truediv__ instead.

This is extracted from https://bazaar.launchpad.net/~bellini666/storm/py3/revision/490 in order to be able to land it independently.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

I'll review this myself since I just extracted it from somebody else's MP.

review: Approve

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 2019-06-07 16:36:44 +0000
3+++ storm/expr.py 2019-08-11 12:18:09 +0000
4@@ -410,6 +410,7 @@
5
6 class Comparable(object):
7 __slots__ = ()
8+ __hash__ = object.__hash__
9
10 def __eq__(self, other):
11 if other is not None and not isinstance(other, (Expr, Variable)):
12@@ -481,6 +482,9 @@
13 other = getattr(self, "variable_factory", Variable)(value=other)
14 return Div(self, other)
15
16+ __floordiv__ = __div__
17+ __truediv__ = __div__
18+
19 def __mod__(self, other):
20 if not isinstance(other, (Expr, Variable)):
21 other = getattr(self, "variable_factory", Variable)(value=other)
22
23=== modified file 'storm/info.py'
24--- storm/info.py 2019-06-05 11:41:07 +0000
25+++ storm/info.py 2019-08-11 12:18:09 +0000
26@@ -148,6 +148,8 @@
27 def __ne__(self, other):
28 return self is not other
29
30+ __hash__ = object.__hash__
31+
32
33 class ObjectInfo(dict):
34
35
36=== modified file 'storm/references.py'
37--- storm/references.py 2019-06-05 11:41:07 +0000
38+++ storm/references.py 2019-08-11 12:18:09 +0000
39@@ -208,6 +208,8 @@
40 def __ne__(self, other):
41 return Not(self == other)
42
43+ __hash__ = object.__hash__
44+
45
46 class ReferenceSet(object):
47

Subscribers

People subscribed via source and target branches

to status/vote changes: