Changes between Version 1 and Version 2 of CodingStyle
- Timestamp:
- 02/17/11 14:56:10 (2 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
CodingStyle
v1 v2 4 4 5 5 Urwid's current version aims to be compatible with Python versions 2.4 - 3.2. These guidelines will help you write Python 2 code that will across those versions (with the help of 2to3) 6 7 == from __future__ == 8 9 We avoid use of ``from __future__`` imports in Urwid. 10 11 This makes the code as much like normal Python 2 code as possible, 12 allows people to easily move code in and out of the library and 13 avoids surprising behaviour. 6 14 7 15 == Strings and Binary Data == … … 13 21 3. Binary data 14 22 15 Unicode strings should be used for all text data in Urwid (mostly in example programs, but also in widgets that come with some default text). 23 Unicode strings should be used for all text data in Urwid (mostly in example programs, but also in widgets that come with some default text). 16 24 17 25 * Use `u"My textual data"` for literal text data everywhere. … … 30 38 * Use `B("bindata\x00\x42\xfe")` for literal binary data 31 39 * Use `bytes()` for an empty binary string (eg. for joining a list of binary values) 32 * Use `bytes(). rjust(x)` for x "space" characters as binary data40 * Use `bytes().ljust(x)` for x "space" characters as binary data 33 41 42 == Unit Tests and Doctests == 34 43 44 When adding new code always include doctests (and documention!) where appropriate and unit tests for simple 45 validation any tricky corner cases. Add unit tests to ``urwid/tests.py`` and when creating a new module add 46 it to the list of doctest modules in the same file. To run the tests run: 35 47 48 {{{ 49 python setup.py test 50 }}} 36 51 37
