Opened 11 years ago

Closed 7 years ago

#2288 closed defect (fixed)

Python3 compatibility changes

Reported by: neteler Owned by: grass-dev@…
Priority: normal Milestone: 7.0.6
Component: Python Version: svn-releasebranch70
Keywords: python Cc:
CPU: Unspecified Platform: Unspecified

Description

In Python 3 exception objects are only available via the "as" keyword, which was introduced in 2.6.

http://docs.pythonsprints.com/python3_porting/py-porting.html#exceptions

I have prepared two patches (relbr7 and trunk) which update all existing Python files accordingly. Files attached for inspection.

Attachments (2)

exception_fixes_relbr7.diff (65.0 KB ) - added by neteler 11 years ago.
Python3 patch for relbranch7
exception_fixes_trunk.diff (65.5 KB ) - added by neteler 11 years ago.
Python3 patch for trunk

Download all attachments as: .zip

Change History (8)

by neteler, 11 years ago

Attachment: exception_fixes_relbr7.diff added

Python3 patch for relbranch7

by neteler, 11 years ago

Attachment: exception_fixes_trunk.diff added

Python3 patch for trunk

in reply to:  description ; comment:1 by glynn, 11 years ago

Replying to neteler:

In Python 3 exception objects are only available via the "as" keyword, which was introduced in 2.6.

We don't support anything earlier than 2.6, right?

In that case, the changes appear to be fine.

2.6 also supports the 3.x-style print() function, with

from __future__ import print_function

as well as the b'...' notation for byte-string literals.

So we can start using those.

It also supports the "with" statement, which should be used where appropriate. Probably the most common use case is for file handling, i.e. using e.g.

with open(filename) as f:
    data = f.read()

rather than

f = open(filename)
data = f.read()
f.close()

The former has the advantage that the file will be closed in the event of an exception (in the latter, the file will only be closed when the file object is garbage-collected, which could be at any point up to program termination).

in reply to:  1 comment:2 by neteler, 11 years ago

Summary: Python3 compatibility: exception needs "as" keywordPython3 compatibility changes

Replying to glynn:

Replying to neteler:

In Python 3 exception objects are only available via the "as" keyword, which was introduced in 2.6.

We don't support anything earlier than 2.6, right?

Right (as documented in REQUIREMENTS.html)

In that case, the changes appear to be fine.

Submitted for relbr7 (r60217) and trunk (r60218).

Since further changes (as mentioned in #comment1) are needed I generalize the ticket summary.

comment:3 by martinl, 9 years ago

Milestone: 7.0.07.0.5

comment:4 by martinl, 8 years ago

Still an issue?

comment:5 by neteler, 8 years ago

Milestone: 7.0.57.0.6

comment:6 by neteler, 7 years ago

Resolution: fixed
Status: newclosed

Fixed long time ago, closing.

Note: See TracTickets for help on using tickets.