pySerialTransfer
pySerialTransfer copied to clipboard
bools mis-classified as ints when using `tx_obj`
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.