PowerBroker2 / pySerialTransfer

Python package to transfer data in a fast, reliable, and packetized form
MIT License
143 stars 35 forks source link

bools mis-classified as ints when using `tx_obj` #91

Open robberwick opened 5 months ago

robberwick commented 5 months ago

While writing tests for tx_obj, I noticed that attempting to call tx_obj(True) resulted in incorrect values being inserted in tx_buff

The culprit is the ordering of the instance type tests. For historic reasons, bool is a subclass of int, so True is an instance of int. (Originally, Python had no bool type, and things that returned truth values returned 1 or 0). Thus, as isinstance(val, int) is performed before isinstance(val, bool), the True is misidentified as an int. Swapping the order of operations fixes this problem.