Edgewall Software

Opened 11 years ago

Last modified 6 years ago

#9536 closed task

Remove Python 2.4 compatibility — at Version 3

Reported by: Remy Blank Owned by: Remy Blank
Priority: normal Milestone: 1.0
Component: general Version: 0.13dev
Severity: normal Keywords: python25
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description (last modified by Remy Blank)

The goal of this task is to remove Python 2.4 compatibility code, and to start using Python 2.5-only features. See what's new in Python 2.5. This includes:

  • Use context managers and the with statement for: database transactions, handling locks, handling files.
  • Use ... if ... else ... expressions instead of the more error-prone ... and ... or ....
  • Use try: except: finally: instead of nested try: finally: and try: except:.
  • Use except Exception: instead of except:.
  • Remove our own implementations for functionality that was introduced in Python 2.5.
  • Use generator expressions instead of list comprehensions where adequate.
  • Use tuple arguments to str.startswith() and str.endswith().
  • Use relative imports for parent, sibling and child modules?

Please add new items to this list as they pop up.

Change History (3)

comment:1 by Christian Boos, 11 years ago

Description: modified (diff)
Keywords: python25 added
Version: 0.13dev

The change concerning the context managers and the with statement mostly concerns the refactor transaction handling topic (#8751), as discussed in the googlegroups:trac-dev:4efe0b99b4e78d23 mail and follow-ups.

But we could also use it for other things, like holding locks.

Slightly related, a few places could also benefit from the unification of try/except/finally.

comment:2 by Christian Boos, 11 years ago

  • Use ... if ... else ... expressions instead of the more error-prone ... and ... or ....

Btw, Genshi supports this at least since the merge of the AST branch (see log:trunk/scripts/ast_generator.py) nearly 2 years ago, so we can also use that in templates (same thing for generator expressions).

comment:3 by Remy Blank, 11 years ago

Description: modified (diff)

Copying items to the description, to get a nice overview. Keep 'em coming!

We should probably also start using except Exception: instead of except:.

What about using relative imports for parent, sibling and child modules (e.g. use from .api import ...)? I wouldn't want to use relative imports for cross-package imports though.

Note: See TracTickets for help on using tickets.