While EnHackathon began last week, today was my first opportunity to join in and give back by fixing Python bugs. I hopped on the Big and Little Endian Unions bus steered by pioneering Tomas Hyland, learnt a few things, and made some progress in helping implement Big and Little Endian Unions.

Background

Tom found an interesting issue to work on - the implementation of Big and Little Endian Unions in the ctypes module (Issue 33178). Tom also did the initial dirty work of finding the issue and scoping it last week, paving the way for me to join in and help him today.

Also tagging along on the Big Endian Bus (Little Endian Bus couldn’t fit all 3 of us) was Anjani, which meant our first task was deciding who should do what. The overall task split nicely into Python and C sub-tasks, which was great as Tom and Anjani had a preference for the C sub-tasks, freeing me to do the Python stuff. Unlike a lot of my colleagues I’m more proficient in Python than C so I was happy with this allocation.

What I Did

There were two tasks I was initially assigned: implement BigEndianUnion and LittleEndianUnion classes, and add associated test cases.

The changes that were required to implement Big(Little)EndianUnion were fairly trivial as the existing Big(Little)EndianStructure provided a blueprint for how to do so. Making the changes, cleaning up common code, and reassuring myself that the changes were sufficient and necessary didn’t take long at all.

The testing portion of my task was less straightforward. In the cpython source there are relevant tests in both Lib/test and Lib/ctypes/test. Getting the tests in Lib/test to run is well documented online and straightforward. The tests in Lib/ctypes/test: less so.

It took me a while to figure out that the way to run a ctypes test module is by running, for example, ./python.exe -m unittest Lib.ctypes.test.test_bitfields. This was in contrast to the tests in Lib/test, which could be run, for example, with ./python.exe -m test test_parser.

With that initial frustration out of the way I then worked my way through tests Tom had earmarked as potentially in need of an update. Again, with the existence of Big(Little)EndianStructure, finding which modules needed test cases for Big(Little)EndianUnion was fairly easy, as was writing the test cases.

Looking forward

There are still some test cases that need writing, especially ones where the difference in behaviour between structures and unions is important. When Tom and Anjani finish making the required C changes I will need to work with them to ensure that the implementation is functional and that the new tests pass. If I find myself waiting on them I can get started on another issue I am interested in - replacing usages of the deprecated asyncore module in various tests (Issue 28533).

I enjoyed my first day of EnHackathon. I learnt more about cpython and unions, and found Tom and Anjani easy to work with. Having said that, I feel that there is a lot more I can give and am eager to make the most of the next few days of EnHackathon.