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
=== modified file 'storm/expr.py'
--- storm/expr.py 2019-06-07 16:36:44 +0000
+++ storm/expr.py 2019-08-11 12:18:09 +0000
@@ -410,6 +410,7 @@
410410
411class Comparable(object):411class Comparable(object):
412 __slots__ = ()412 __slots__ = ()
413 __hash__ = object.__hash__
413414
414 def __eq__(self, other):415 def __eq__(self, other):
415 if other is not None and not isinstance(other, (Expr, Variable)):416 if other is not None and not isinstance(other, (Expr, Variable)):
@@ -481,6 +482,9 @@
481 other = getattr(self, "variable_factory", Variable)(value=other)482 other = getattr(self, "variable_factory", Variable)(value=other)
482 return Div(self, other)483 return Div(self, other)
483484
485 __floordiv__ = __div__
486 __truediv__ = __div__
487
484 def __mod__(self, other):488 def __mod__(self, other):
485 if not isinstance(other, (Expr, Variable)):489 if not isinstance(other, (Expr, Variable)):
486 other = getattr(self, "variable_factory", Variable)(value=other)490 other = getattr(self, "variable_factory", Variable)(value=other)
487491
=== modified file 'storm/info.py'
--- storm/info.py 2019-06-05 11:41:07 +0000
+++ storm/info.py 2019-08-11 12:18:09 +0000
@@ -148,6 +148,8 @@
148 def __ne__(self, other):148 def __ne__(self, other):
149 return self is not other149 return self is not other
150150
151 __hash__ = object.__hash__
152
151153
152class ObjectInfo(dict):154class ObjectInfo(dict):
153155
154156
=== modified file 'storm/references.py'
--- storm/references.py 2019-06-05 11:41:07 +0000
+++ storm/references.py 2019-08-11 12:18:09 +0000
@@ -208,6 +208,8 @@
208 def __ne__(self, other):208 def __ne__(self, other):
209 return Not(self == other)209 return Not(self == other)
210210
211 __hash__ = object.__hash__
212
211213
212class ReferenceSet(object):214class ReferenceSet(object):
213215

Subscribers

People subscribed via source and target branches

to status/vote changes: