What's the best way of distinguishing bools from numbers in Python?
Question: I have an application where I need to be able to distinguish between numbers
and bools as quickly as possible. What are the alternatives apart from running
`isinstance(value, bool)` first?

Edit: Thanks for the suggestions. Actually, what I want to be able to do have
a check for numbers that leaves out bools so that I can reorder my checks
(numbers are far more prevalent) and improve my negacalls. `isinstance()`
itself is fast enough. The `x is True or x is False` is intriguing.


Answer: So, Padraic Cunningham suggests, that the following might be a bit faster. My
own quick experiments with `cProfile`-ing it haven't shown any difference:

    
    
    isbool = value is True or value is False
    

I assume that's as fast as you can get: Two non-type-coercing comparisons.

**Edit:** I replayed the timing tests from @user 5061 and added my statement.
This is my result:

    
    
    >>> import timeit
    >>> stmt1 = "isinstance(123, bool)"
    >>> stmt2 = "123 is True or 123 is False"
    >>> t1 = timeit.timeit(stmt1)
    >>> t2 = timeit.timeit(stmt2)
    >>> print t1
    0.172112941742
    >>> print t2
    0.0690350532532
    

**Edit 2:** Note, that I'm using Python 2.7 here. @user 5061 might use Python
3 (telling from the `print()` function), so any solution provided here should
be tested by OP before putting in production, for YMMV.

