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.
While writing tests for
tx_obj
, I noticed that attempting to calltx_obj(True)
resulted in incorrect values being inserted intx_buff
The culprit is the ordering of the instance type tests. For historic reasons,
bool
is a subclass ofint
, soTrue
is an instance ofint
. (Originally, Python had nobool
type, and things that returned truth values returned 1 or 0). Thus, asisinstance(val, int)
is performed beforeisinstance(val, bool)
, theTrue
is misidentified as an int. Swapping the order of operations fixes this problem.