Differences between revisions 4 and 5
Revision 4 as of 2018-07-09 11:34:32
Size: 1113
Editor: chapoton
Comment:
Revision 5 as of 2018-07-25 19:48:22
Size: 0
Editor: chapoton
Comment: useless and disturbing
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
For work on the python3-compatible version of sage, see [[Python3-compatible code]]

== matplotlib's experiences porting to Python 3 ==

* Drop support for < 2.6 (master currently supports 2.4)

* Easy things (that 2to3 handles pretty well):

  * print function

  * "in" vs. "has_key"

  * "except Exception as exc" syntax

  * stdlib stuff

* 2to3 is slooooow

* Unicode

  * Unicode literals by default

  * no implicit conversion between Unicode and bytes (encoding must be explicit)

  * files must have explicit Unicode encoding, or be binary -- hard to do both at same time

* Exceptions

{{{
  exceptions_found = []
  try:
      do_something()
  except Exception as e:
      exceptions_found.append(e)
}}}
  
Since e now has a __traceback__ member, this creates a cycle e -> traceback -> current stack frame -> e. This cycle will keep alive all local variables in all frames beneath the source of the exception.

* C/C++ issues

  * For us, mostly hidden by using CXX

  * PyCObject was dropped in Python 3.2 -- had to port CXX to use its replacement PyCapsule