I've written a pure-Python module for Python 3.0/3.1 which I'd also like to make it compatible with 2.x (probably just 2.6/2.7) in order to make it available to the widest possible audience.
The module is concerned with reading and writing a set of related file formats, so the differences between 2.x and 3.x versions would be slight — e.g. io.BytesIO
instead of StringIO.StringIO
— but not all of them are easily handled via try/except blocks, such as setting metaclasses.
What's the correct way to handle this? Two nearly-identical codebases which must be kept in sync or one codebase sprinkled with feature detection? A single, clean codebase plus 2to3 or 3to2?