Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(265)

Issue 6028046: issue329

Can't Edit
Can't Publish+Mail
Start Review
Created:
12 years ago by jendrik
Modified:
12 years ago
Reviewers:
malte.helmert, Malte
Visibility:
Public.

Description

python3 compatibility

Patch Set 1 #

Total comments: 51

Patch Set 2 : check all python versions #

Unified diffs Side-by-side diffs Delta from patch set Stats (+10 lines, -2 lines) Patch
M misc/test-translator View 1 1 chunk +10 lines, -2 lines 0 comments Download

Messages

Total messages: 3
Malte
http://codereview.appspot.com/6028046/diff/1/misc/test-translator.py File misc/test-translator.py (right): http://codereview.appspot.com/6028046/diff/1/misc/test-translator.py#newcode37 misc/test-translator.py:37: tasks.sort() "f in sorted(os.listdir..." + tasks.sort() looks redundant http://codereview.appspot.com/6028046/diff/1/src/translate/build_model.py ...
12 years ago (2012-04-13 16:08:53 UTC) #1
jendrik
I have incorporated your comments and will run an experiment now. http://codereview.appspot.com/6028046/diff/1/misc/test-translator.py File misc/test-translator.py (right): ...
12 years ago (2012-04-14 16:23:24 UTC) #2
Malte
12 years ago (2012-04-14 17:11:25 UTC) #3
A few more comments.

http://codereview.appspot.com/6028046/diff/1/src/translate/pddl/conditions.py
File src/translate/pddl/conditions.py (right):

http://codereview.appspot.com/6028046/diff/1/src/translate/pddl/conditions.py...
src/translate/pddl/conditions.py:72: return self.hash < other.hash
On 2012/04/14 16:23:24, jendrik wrote:
> On 2012/04/13 16:08:53, Malte wrote:
> > Is it enough to define __lt__? Why?
> I added the other ones to be on the safe side.

Not sure which ones you added, but to be clear: it is in general necessary to
define __eq__, __ne__, __lt__ and __le__ to get the full set of comparisons with
all Pythons.

__gt__ and __ge__ are automatically defined via __lt__ and __le__, but there is
no automatic definition of (e.g). __le__ via __lt__ and __eq__ in any Python
version.

In Python 3.2 and possibly earlier versions of Python 3, __ne__ is also
implemented by default if you have __eq__. But this is not true in Python 2.x.

In summary:
- For Python 2, we need __eq__, __ne__, __lt__ and __le__
  (or __cmp__ instead of all those).
- For Python 3, we need __eq__, __lt__ and __le__

There are currently discussions to define __le__ via __lt__ and __eq__ in the
future, but from what I recall the proposal doesn't seem to be very positively
received.

http://codereview.appspot.com/6028046/diff/1/src/translate/pddl/conditions.py...
src/translate/pddl/conditions.py:128: __hash__ = Condition.__hash__
On 2012/04/14 16:23:24, jendrik wrote:
> On 2012/04/13 16:08:53, Malte wrote:
> > That doesn't seem to do anything useful?
> > __hash__ would be inherited from the superclass anyway.
> 
> I was surprised as well. From
> http://docs.python.org/release/3.2/reference/datamodel.html#object.__hash__:
> "If a class that overrides __eq__() needs to retain the implementation of
> __hash__() from a parent class, the interpreter must be told this explicitly
by
> setting __hash__ = <ParentClass>.__hash__. Otherwise the inheritance of
> __hash__() will be blocked, just as if __hash__ had been explicitly set to
> None."

Aha! Can you change the comment a bit to reflect what is going on? Like

# Defining __eq__ blocks inheritance of __hash__, so must set it explicitly.

http://codereview.appspot.com/6028046/diff/1/src/translate/pddl/pddl_types.py
File src/translate/pddl/pddl_types.py (right):

http://codereview.appspot.com/6028046/diff/1/src/translate/pddl/pddl_types.py...
src/translate/pddl/pddl_types.py:54: from . import conditions
On 2012/04/14 16:23:24, jendrik wrote:
> On 2012/04/13 16:08:53, Malte wrote:
> > Is there no better way to resolve this?
> I couldn't come up with a simple solution for this.

Can you add a

# TODO: Try to resolve the cyclic import differently

or something like this?
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b