Skip to content

A few python3 compatibility additions

Duncan Macleod requested to merge (removed):python3 into master

This merge makes some (hopefully) trivial modifications to enhance python3 compatibility, in summary:

  • [fb3748b5] use print() function instead of print statement
  • [9cdb5bda] use relative imports where appropriate, and __builtin__ -> builtins
  • [3314d74c] combine dict.items using list
  • [6b42f2ef] handle missing long in python3

One big remaining problem with python3 compatibility is the custom import logic under GuardSystem._import. In python3 builtins.__import__ doesn't accept level=-1 which is the current default, since automagic discovery of relative vs absolute imports was removed.

However, the GuardSystem._import function is only called from itself, so I think it would be easily to rewrite to use importlib.import_module, but don't understand the reasoning behind the current code to be confident of doing this myself.

Finally, the usercode is not python3 compatible to start with, which means testing this properly is tricksy, hopefully @jameson.rollins can look through the changes closely to see if I have broken anything.

Merge request reports