Use forward-compatible python (part 2)

### Motivation
Continuing the work started in #884, this time using [2to3](https://docs.python.org/2.7/library/2to3.html) in a very conservative way: only 2.7-compatible transformations are applied.

### Changelog
* Use set literals (new in Python 2.7).
* Use `isinstance` instead of `type`, to ensure proper functionality in case of subclassing.